- 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.
47 lines
890 B
Go
47 lines
890 B
Go
package auth
|
||
|
||
import (
|
||
"carrotskin/pkg/config"
|
||
"fmt"
|
||
"sync"
|
||
)
|
||
|
||
var (
|
||
// jwtServiceInstance 全局JWT服务实例
|
||
jwtServiceInstance *JWTService
|
||
// once 确保只初始化一次
|
||
once sync.Once
|
||
// initError 初始化错误
|
||
)
|
||
|
||
// Init 初始化JWT服务(线程安全,只会执行一次)
|
||
func Init(cfg config.JWTConfig) error {
|
||
once.Do(func() {
|
||
jwtServiceInstance = NewJWTService(cfg.Secret, cfg.ExpireHours)
|
||
})
|
||
return nil
|
||
}
|
||
|
||
// GetJWTService 获取JWT服务实例(线程安全)
|
||
func GetJWTService() (*JWTService, error) {
|
||
if jwtServiceInstance == nil {
|
||
return nil, fmt.Errorf("JWT服务未初始化,请先调用 auth.Init()")
|
||
}
|
||
return jwtServiceInstance, nil
|
||
}
|
||
|
||
// MustGetJWTService 获取JWT服务实例,如果未初始化则panic
|
||
func MustGetJWTService() *JWTService {
|
||
service, err := GetJWTService()
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
return service
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|