- Introduced new API endpoints for rendering textures, avatars, capes, and previews, enhancing the texture handling capabilities. - Implemented corresponding service methods in the TextureHandler to process rendering requests and return appropriate responses. - Updated the TextureRenderService interface to include methods for rendering textures, avatars, and capes, along with their respective parameters. - Enhanced error handling for invalid texture IDs and added support for different rendering types and formats. - Updated go.mod to include the webp library for image processing.
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package config
|
||
|
||
import (
|
||
"fmt"
|
||
"sync"
|
||
)
|
||
|
||
var (
|
||
// configInstance 全局配置实例
|
||
configInstance *Config
|
||
// rustFSConfigInstance 全局RustFS配置实例
|
||
rustFSConfigInstance *RustFSConfig
|
||
// once 确保只初始化一次
|
||
once sync.Once
|
||
// initError 初始化错误
|
||
initError error
|
||
)
|
||
|
||
// Init 初始化配置(线程安全,只会执行一次)
|
||
func Init() error {
|
||
once.Do(func() {
|
||
configInstance, initError = Load()
|
||
if initError != nil {
|
||
return
|
||
}
|
||
rustFSConfigInstance = &configInstance.RustFS
|
||
})
|
||
return initError
|
||
}
|
||
|
||
// GetConfig 获取配置实例(线程安全)
|
||
func GetConfig() (*Config, error) {
|
||
if configInstance == nil {
|
||
return nil, fmt.Errorf("配置未初始化,请先调用 config.Init()")
|
||
}
|
||
return configInstance, nil
|
||
}
|
||
|
||
// MustGetConfig 获取配置实例,如果未初始化则panic
|
||
func MustGetConfig() *Config {
|
||
cfg, err := GetConfig()
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
return cfg
|
||
}
|
||
|
||
// GetRustFSConfig 获取RustFS配置实例(线程安全)
|
||
func GetRustFSConfig() (*RustFSConfig, error) {
|
||
if rustFSConfigInstance == nil {
|
||
return nil, fmt.Errorf("配置未初始化,请先调用 config.Init()")
|
||
}
|
||
return rustFSConfigInstance, nil
|
||
}
|
||
|
||
// MustGetRustFSConfig 获取RustFS配置实例,如果未初始化则panic
|
||
func MustGetRustFSConfig() *RustFSConfig {
|
||
cfg, err := GetRustFSConfig()
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
return cfg
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|