Add symbol definitions, code cleanup
This commit is contained in:
132
src/config.go
132
src/config.go
@@ -7,6 +7,110 @@ import (
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultConfig is the default configuration values used by the application.
|
||||
DefaultConfig *Config = &Config{
|
||||
Host: "127.0.0.1",
|
||||
Port: 3001,
|
||||
Redis: RedisConfig{
|
||||
Host: "127.0.0.1",
|
||||
Port: 6379,
|
||||
User: "",
|
||||
Password: "",
|
||||
Database: 0,
|
||||
},
|
||||
Routes: RoutesConfig{
|
||||
Face: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
Head: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
FullBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
FrontBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
BackBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
LeftBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
RightBody: RouteConfig{
|
||||
DefaultOverlay: true,
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
DefaultScale: 4,
|
||||
MinScale: 1,
|
||||
MaxScale: 64,
|
||||
},
|
||||
RawSkin: RouteConfig{
|
||||
DefaultDownload: false,
|
||||
DefaultFallback: true,
|
||||
},
|
||||
},
|
||||
Cache: CacheConfig{
|
||||
UUIDCacheDuration: time.Hour * 168,
|
||||
SkinCacheDuration: time.Hour * 12,
|
||||
RenderCacheDuration: time.Hour * 12,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// Config is the root configuration object for the application.
|
||||
type Config struct {
|
||||
Host string `yaml:"host"`
|
||||
Port uint16 `yaml:"port"`
|
||||
Redis RedisConfig `yaml:"redis"`
|
||||
Routes RoutesConfig `yaml:"routes"`
|
||||
Cache CacheConfig `yaml:"cache"`
|
||||
}
|
||||
|
||||
// RoutesConfig is the configuration data of all API routes.
|
||||
type RoutesConfig struct {
|
||||
Face RouteConfig `yaml:"face"`
|
||||
Head RouteConfig `yaml:"head"`
|
||||
FullBody RouteConfig `yaml:"full_body"`
|
||||
FrontBody RouteConfig `yaml:"front_body"`
|
||||
BackBody RouteConfig `yaml:"back_body"`
|
||||
LeftBody RouteConfig `yaml:"left_body"`
|
||||
RightBody RouteConfig `yaml:"right_body"`
|
||||
RawSkin RouteConfig `yaml:"raw_skin"`
|
||||
}
|
||||
|
||||
// RouteConfig is the configuration data used by a single API route.
|
||||
type RouteConfig struct {
|
||||
DefaultScale int `yaml:"default_scale"`
|
||||
DefaultOverlay bool `yaml:"default_overlay"`
|
||||
@@ -16,6 +120,7 @@ type RouteConfig struct {
|
||||
MaxScale int `yaml:"max_scale"`
|
||||
}
|
||||
|
||||
// RedisConfig is the configuration data used to connect to Redis.
|
||||
type RedisConfig struct {
|
||||
Host string `yaml:"host"`
|
||||
Port uint16 `yaml:"port"`
|
||||
@@ -24,28 +129,15 @@ type RedisConfig struct {
|
||||
Database int `yaml:"database"`
|
||||
}
|
||||
|
||||
type Configuration struct {
|
||||
Host string `yaml:"host"`
|
||||
Port uint16 `yaml:"port"`
|
||||
Redis RedisConfig `yaml:"redis"`
|
||||
Routes struct {
|
||||
Face RouteConfig `yaml:"face"`
|
||||
Head RouteConfig `yaml:"head"`
|
||||
FullBody RouteConfig `yaml:"full_body"`
|
||||
FrontBody RouteConfig `yaml:"front_body"`
|
||||
BackBody RouteConfig `yaml:"back_body"`
|
||||
LeftBody RouteConfig `yaml:"left_body"`
|
||||
RightBody RouteConfig `yaml:"right_body"`
|
||||
RawSkin RouteConfig `yaml:"raw_skin"`
|
||||
} `yaml:"routes"`
|
||||
Cache struct {
|
||||
UUIDCacheDuration time.Duration `yaml:"uuid_cache_duration"`
|
||||
SkinCacheDuration time.Duration `yaml:"skin_cache_duration"`
|
||||
RenderCacheDuration time.Duration `yaml:"render_cache_duration"`
|
||||
} `yaml:"cache"`
|
||||
// CacheConfig is the configuration data used to set TTL values for Redis keys.
|
||||
type CacheConfig struct {
|
||||
UUIDCacheDuration time.Duration `yaml:"uuid_cache_duration"`
|
||||
SkinCacheDuration time.Duration `yaml:"skin_cache_duration"`
|
||||
RenderCacheDuration time.Duration `yaml:"render_cache_duration"`
|
||||
}
|
||||
|
||||
func (c *Configuration) ReadFile(file string) error {
|
||||
// ReadFile reads the configuration from the file and parses it as YAML.
|
||||
func (c *Config) ReadFile(file string) error {
|
||||
data, err := os.ReadFile(file)
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user