- 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.
56 lines
946 B
Go
56 lines
946 B
Go
package storage
|
||
|
||
import (
|
||
"carrotskin/pkg/config"
|
||
"fmt"
|
||
"sync"
|
||
)
|
||
|
||
var (
|
||
// clientInstance 全局存储客户端实例
|
||
clientInstance *StorageClient
|
||
// once 确保只初始化一次
|
||
once sync.Once
|
||
// initError 初始化错误
|
||
initError error
|
||
)
|
||
|
||
// Init 初始化存储客户端(线程安全,只会执行一次)
|
||
func Init(cfg config.RustFSConfig) error {
|
||
once.Do(func() {
|
||
clientInstance, initError = NewStorage(cfg)
|
||
if initError != nil {
|
||
return
|
||
}
|
||
})
|
||
return initError
|
||
}
|
||
|
||
// GetClient 获取存储客户端实例(线程安全)
|
||
func GetClient() (*StorageClient, error) {
|
||
if clientInstance == nil {
|
||
return nil, fmt.Errorf("存储客户端未初始化,请先调用 storage.Init()")
|
||
}
|
||
return clientInstance, nil
|
||
}
|
||
|
||
// MustGetClient 获取存储客户端实例,如果未初始化则panic
|
||
func MustGetClient() *StorageClient {
|
||
client, err := GetClient()
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
return client
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|