Rename config variable
This commit is contained in:
@@ -38,7 +38,7 @@ func GetResultCacheKey(uuid, renderType string, opts *QueryParams) (string, erro
|
||||
|
||||
// GetCachedRenderResult returns the render result from Redis cache, or nil if it does not exist or cache is disabled.
|
||||
func GetCachedRenderResult(renderType, uuid string, opts *QueryParams) ([]byte, error) {
|
||||
if conf.Cache.RenderCacheDuration == nil {
|
||||
if config.Cache.RenderCacheDuration == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func GetCachedRenderResult(renderType, uuid string, opts *QueryParams) ([]byte,
|
||||
|
||||
// SetCachedRenderResult puts the render result into cache, or does nothing is cache is disabled.
|
||||
func SetCachedRenderResult(renderType, uuid string, opts *QueryParams, data []byte) error {
|
||||
if conf.Cache.RenderCacheDuration == nil {
|
||||
if config.Cache.RenderCacheDuration == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func SetCachedRenderResult(renderType, uuid string, opts *QueryParams, data []by
|
||||
return err
|
||||
}
|
||||
|
||||
return r.Set(key, data, *conf.Cache.RenderCacheDuration)
|
||||
return r.Set(key, data, *config.Cache.RenderCacheDuration)
|
||||
}
|
||||
|
||||
// GetCachedSkin returns the raw skin of a player by UUID from the cache, also returning if the player has a slim player model.
|
||||
@@ -81,7 +81,7 @@ func GetCachedSkin(uuid string) (*image.NRGBA, bool, error) {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if conf.Environment == "development" {
|
||||
if config.Environment == "development" {
|
||||
log.Printf("Retrieved player skin from cache (uuid=%s, slim=%v)\n", uuid, slim)
|
||||
}
|
||||
|
||||
|
||||
12
src/main.go
12
src/main.go
@@ -23,18 +23,18 @@ var (
|
||||
},
|
||||
})
|
||||
r *Redis = &Redis{}
|
||||
conf *Config = &Config{}
|
||||
config *Config = &Config{}
|
||||
instanceID uint16 = 0
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
if err = conf.ReadFile("config.yml"); err != nil {
|
||||
if err = config.ReadFile("config.yml"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err = r.Connect(conf.Redis); err != nil {
|
||||
if err = r.Connect(config.Redis); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func init() {
|
||||
|
||||
app.Use(recover.New())
|
||||
|
||||
if conf.Environment == "development" {
|
||||
if config.Environment == "development" {
|
||||
app.Use(cors.New(cors.Config{
|
||||
AllowOrigins: "*",
|
||||
AllowMethods: "HEAD,OPTIONS,GET",
|
||||
@@ -75,9 +75,9 @@ func main() {
|
||||
|
||||
defer r.Close()
|
||||
|
||||
log.Printf("Listening on %s:%d\n", conf.Host, conf.Port+instanceID)
|
||||
log.Printf("Listening on %s:%d\n", config.Host, config.Port+instanceID)
|
||||
|
||||
if err := app.Listen(fmt.Sprintf("%s:%d", conf.Host, conf.Port+instanceID)); err != nil {
|
||||
if err := app.Listen(fmt.Sprintf("%s:%d", config.Host, config.Port+instanceID)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func ListHandler(ctx *fiber.Ctx) error {
|
||||
|
||||
// SkinHandler is the API handler used for the `/skin/:uuid` route.
|
||||
func SkinHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, conf.Routes.RawSkin)
|
||||
opts := ParseQueryParams(ctx, config.Routes.RawSkin)
|
||||
|
||||
uuid, ok := ParseUUID(ctx.Params("uuid"))
|
||||
|
||||
@@ -94,7 +94,7 @@ func SkinHandler(ctx *fiber.Ctx) error {
|
||||
|
||||
// FaceHandler is the API handler used for the `/face/:uuid` route.
|
||||
func FaceHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, conf.Routes.Face)
|
||||
opts := ParseQueryParams(ctx, config.Routes.Face)
|
||||
|
||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||
|
||||
@@ -125,7 +125,7 @@ func FaceHandler(ctx *fiber.Ctx) error {
|
||||
|
||||
// HeadHandler is the API handler used for the `/head/:uuid` route.
|
||||
func HeadHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, conf.Routes.Head)
|
||||
opts := ParseQueryParams(ctx, config.Routes.Head)
|
||||
|
||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||
|
||||
@@ -156,7 +156,7 @@ func HeadHandler(ctx *fiber.Ctx) error {
|
||||
|
||||
// FullBodyHandler is the API handler used for the `/body/full/:uuid` route.
|
||||
func FullBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, conf.Routes.FullBody)
|
||||
opts := ParseQueryParams(ctx, config.Routes.FullBody)
|
||||
|
||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||
|
||||
@@ -187,7 +187,7 @@ func FullBodyHandler(ctx *fiber.Ctx) error {
|
||||
|
||||
// FrontBodyHandler is the API handler used for the `/body/front/:uuid` route.
|
||||
func FrontBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, conf.Routes.FrontBody)
|
||||
opts := ParseQueryParams(ctx, config.Routes.FrontBody)
|
||||
|
||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||
|
||||
@@ -218,7 +218,7 @@ func FrontBodyHandler(ctx *fiber.Ctx) error {
|
||||
|
||||
// BackBodyHandler is the API handler used for the `/body/back/:uuid` route.
|
||||
func BackBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, conf.Routes.BackBody)
|
||||
opts := ParseQueryParams(ctx, config.Routes.BackBody)
|
||||
|
||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||
|
||||
@@ -249,7 +249,7 @@ func BackBodyHandler(ctx *fiber.Ctx) error {
|
||||
|
||||
// LeftBodyHandler is the API handler used for the `/body/left/:uuid` route.
|
||||
func LeftBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, conf.Routes.LeftBody)
|
||||
opts := ParseQueryParams(ctx, config.Routes.LeftBody)
|
||||
|
||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||
|
||||
@@ -280,7 +280,7 @@ func LeftBodyHandler(ctx *fiber.Ctx) error {
|
||||
|
||||
// RightBodyHandler is the API handler used for the `/body/right/:uuid` route.
|
||||
func RightBodyHandler(ctx *fiber.Ctx) error {
|
||||
opts := ParseQueryParams(ctx, conf.Routes.RightBody)
|
||||
opts := ParseQueryParams(ctx, config.Routes.RightBody)
|
||||
|
||||
uuid, ok := ParseUUID(ExtractUUID(ctx))
|
||||
|
||||
|
||||
18
src/util.go
18
src/util.go
@@ -58,7 +58,7 @@ func Clamp[T int | uint | int8 | uint8 | int16 | uint16 | int32 | uint32 | int64
|
||||
|
||||
// Render will render the image using the specified details and return the result.
|
||||
func Render(renderType, uuid string, rawSkin *image.NRGBA, isSlim bool, opts *QueryParams) ([]byte, bool, error) {
|
||||
if conf.Cache.EnableLocks {
|
||||
if config.Cache.EnableLocks {
|
||||
mutex := r.NewMutex(fmt.Sprintf("render-lock:%s-%d-%t-%s", renderType, opts.Scale, opts.Overlay, uuid))
|
||||
mutex.Lock()
|
||||
|
||||
@@ -72,7 +72,7 @@ func Render(renderType, uuid string, rawSkin *image.NRGBA, isSlim bool, opts *Qu
|
||||
}
|
||||
|
||||
if cache != nil {
|
||||
if conf.Environment == "development" {
|
||||
if config.Environment == "development" {
|
||||
log.Printf("Retrieved render from cache (type=%s, uuid=%s, slim=%v, scale=%d)\n", renderType, uuid, isSlim, opts.Scale)
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func Render(renderType, uuid string, rawSkin *image.NRGBA, isSlim bool, opts *Qu
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if conf.Environment == "development" {
|
||||
if config.Environment == "development" {
|
||||
log.Printf("Rendered image (type=%s, uuid=%s, slim=%v, scale=%d)\n", renderType, uuid, isSlim, opts.Scale)
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func FetchImage(url string) (*image.NRGBA, error) {
|
||||
|
||||
// GetPlayerSkin fetches the skin of the Minecraft player by the UUID.
|
||||
func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
||||
if conf.Cache.EnableLocks {
|
||||
if config.Cache.EnableLocks {
|
||||
mutex := r.NewMutex(fmt.Sprintf("skin-lock:%s", uuid))
|
||||
mutex.Lock()
|
||||
|
||||
@@ -205,7 +205,7 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
||||
}
|
||||
|
||||
// Get skin from cache, and return if it exists
|
||||
if conf.Cache.SkinCacheDuration != nil {
|
||||
if config.Cache.SkinCacheDuration != nil {
|
||||
rawSkin, slim, err := GetCachedSkin(uuid)
|
||||
|
||||
if err != nil {
|
||||
@@ -282,13 +282,13 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
||||
}
|
||||
|
||||
// Put the skin into cache so it can be used for future requests
|
||||
if conf.Cache.SkinCacheDuration != nil {
|
||||
if err = r.Set(fmt.Sprintf("skin:%s", uuid), rawSkin, *conf.Cache.SkinCacheDuration); err != nil {
|
||||
if config.Cache.SkinCacheDuration != nil {
|
||||
if err = r.Set(fmt.Sprintf("skin:%s", uuid), rawSkin, *config.Cache.SkinCacheDuration); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if isSlim {
|
||||
if err = r.Set(fmt.Sprintf("slim:%s", uuid), "true", *conf.Cache.SkinCacheDuration); err != nil {
|
||||
if err = r.Set(fmt.Sprintf("slim:%s", uuid), "true", *config.Cache.SkinCacheDuration); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
} else {
|
||||
@@ -298,7 +298,7 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if conf.Environment == "development" {
|
||||
if config.Environment == "development" {
|
||||
log.Printf("Fetched player skin from Mojang (uuid=%s, slim=%v)\n", uuid, isSlim)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user