Rename config variable

This commit is contained in:
Jacob Gunther
2023-08-05 21:55:13 -05:00
parent 2e08b91250
commit 44d43944cf
4 changed files with 27 additions and 27 deletions

View File

@@ -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. // 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) { func GetCachedRenderResult(renderType, uuid string, opts *QueryParams) ([]byte, error) {
if conf.Cache.RenderCacheDuration == nil { if config.Cache.RenderCacheDuration == nil {
return nil, 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. // SetCachedRenderResult puts the render result into cache, or does nothing is cache is disabled.
func SetCachedRenderResult(renderType, uuid string, opts *QueryParams, data []byte) error { func SetCachedRenderResult(renderType, uuid string, opts *QueryParams, data []byte) error {
if conf.Cache.RenderCacheDuration == nil { if config.Cache.RenderCacheDuration == nil {
return nil return nil
} }
@@ -63,7 +63,7 @@ func SetCachedRenderResult(renderType, uuid string, opts *QueryParams, data []by
return err 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. // 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 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) log.Printf("Retrieved player skin from cache (uuid=%s, slim=%v)\n", uuid, slim)
} }

View File

@@ -23,18 +23,18 @@ var (
}, },
}) })
r *Redis = &Redis{} r *Redis = &Redis{}
conf *Config = &Config{} config *Config = &Config{}
instanceID uint16 = 0 instanceID uint16 = 0
) )
func init() { func init() {
var err error var err error
if err = conf.ReadFile("config.yml"); err != nil { if err = config.ReadFile("config.yml"); err != nil {
log.Fatal(err) log.Fatal(err)
} }
if err = r.Connect(conf.Redis); err != nil { if err = r.Connect(config.Redis); err != nil {
log.Fatal(err) log.Fatal(err)
} }
@@ -42,7 +42,7 @@ func init() {
app.Use(recover.New()) app.Use(recover.New())
if conf.Environment == "development" { if config.Environment == "development" {
app.Use(cors.New(cors.Config{ app.Use(cors.New(cors.Config{
AllowOrigins: "*", AllowOrigins: "*",
AllowMethods: "HEAD,OPTIONS,GET", AllowMethods: "HEAD,OPTIONS,GET",
@@ -75,9 +75,9 @@ func main() {
defer r.Close() 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) panic(err)
} }
} }

View File

@@ -65,7 +65,7 @@ func ListHandler(ctx *fiber.Ctx) error {
// SkinHandler is the API handler used for the `/skin/:uuid` route. // SkinHandler is the API handler used for the `/skin/:uuid` route.
func SkinHandler(ctx *fiber.Ctx) error { func SkinHandler(ctx *fiber.Ctx) error {
opts := ParseQueryParams(ctx, conf.Routes.RawSkin) opts := ParseQueryParams(ctx, config.Routes.RawSkin)
uuid, ok := ParseUUID(ctx.Params("uuid")) 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. // FaceHandler is the API handler used for the `/face/:uuid` route.
func FaceHandler(ctx *fiber.Ctx) error { func FaceHandler(ctx *fiber.Ctx) error {
opts := ParseQueryParams(ctx, conf.Routes.Face) opts := ParseQueryParams(ctx, config.Routes.Face)
uuid, ok := ParseUUID(ExtractUUID(ctx)) 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. // HeadHandler is the API handler used for the `/head/:uuid` route.
func HeadHandler(ctx *fiber.Ctx) error { func HeadHandler(ctx *fiber.Ctx) error {
opts := ParseQueryParams(ctx, conf.Routes.Head) opts := ParseQueryParams(ctx, config.Routes.Head)
uuid, ok := ParseUUID(ExtractUUID(ctx)) 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. // FullBodyHandler is the API handler used for the `/body/full/:uuid` route.
func FullBodyHandler(ctx *fiber.Ctx) error { func FullBodyHandler(ctx *fiber.Ctx) error {
opts := ParseQueryParams(ctx, conf.Routes.FullBody) opts := ParseQueryParams(ctx, config.Routes.FullBody)
uuid, ok := ParseUUID(ExtractUUID(ctx)) 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. // FrontBodyHandler is the API handler used for the `/body/front/:uuid` route.
func FrontBodyHandler(ctx *fiber.Ctx) error { func FrontBodyHandler(ctx *fiber.Ctx) error {
opts := ParseQueryParams(ctx, conf.Routes.FrontBody) opts := ParseQueryParams(ctx, config.Routes.FrontBody)
uuid, ok := ParseUUID(ExtractUUID(ctx)) 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. // BackBodyHandler is the API handler used for the `/body/back/:uuid` route.
func BackBodyHandler(ctx *fiber.Ctx) error { func BackBodyHandler(ctx *fiber.Ctx) error {
opts := ParseQueryParams(ctx, conf.Routes.BackBody) opts := ParseQueryParams(ctx, config.Routes.BackBody)
uuid, ok := ParseUUID(ExtractUUID(ctx)) 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. // LeftBodyHandler is the API handler used for the `/body/left/:uuid` route.
func LeftBodyHandler(ctx *fiber.Ctx) error { func LeftBodyHandler(ctx *fiber.Ctx) error {
opts := ParseQueryParams(ctx, conf.Routes.LeftBody) opts := ParseQueryParams(ctx, config.Routes.LeftBody)
uuid, ok := ParseUUID(ExtractUUID(ctx)) 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. // RightBodyHandler is the API handler used for the `/body/right/:uuid` route.
func RightBodyHandler(ctx *fiber.Ctx) error { func RightBodyHandler(ctx *fiber.Ctx) error {
opts := ParseQueryParams(ctx, conf.Routes.RightBody) opts := ParseQueryParams(ctx, config.Routes.RightBody)
uuid, ok := ParseUUID(ExtractUUID(ctx)) uuid, ok := ParseUUID(ExtractUUID(ctx))

View File

@@ -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. // 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) { 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 := r.NewMutex(fmt.Sprintf("render-lock:%s-%d-%t-%s", renderType, opts.Scale, opts.Overlay, uuid))
mutex.Lock() mutex.Lock()
@@ -72,7 +72,7 @@ func Render(renderType, uuid string, rawSkin *image.NRGBA, isSlim bool, opts *Qu
} }
if cache != nil { 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) 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 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) 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. // GetPlayerSkin fetches the skin of the Minecraft player by the UUID.
func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) { 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 := r.NewMutex(fmt.Sprintf("skin-lock:%s", uuid))
mutex.Lock() mutex.Lock()
@@ -205,7 +205,7 @@ func GetPlayerSkin(uuid string) (*image.NRGBA, bool, error) {
} }
// Get skin from cache, and return if it exists // Get skin from cache, and return if it exists
if conf.Cache.SkinCacheDuration != nil { if config.Cache.SkinCacheDuration != nil {
rawSkin, slim, err := GetCachedSkin(uuid) rawSkin, slim, err := GetCachedSkin(uuid)
if err != nil { 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 // Put the skin into cache so it can be used for future requests
if conf.Cache.SkinCacheDuration != nil { if config.Cache.SkinCacheDuration != nil {
if err = r.Set(fmt.Sprintf("skin:%s", uuid), rawSkin, *conf.Cache.SkinCacheDuration); err != nil { if err = r.Set(fmt.Sprintf("skin:%s", uuid), rawSkin, *config.Cache.SkinCacheDuration); err != nil {
return nil, false, err return nil, false, err
} }
if isSlim { 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 return nil, false, err
} }
} else { } 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) log.Printf("Fetched player skin from Mojang (uuid=%s, slim=%v)\n", uuid, isSlim)
} }