- 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.
58 lines
909 B
Go
58 lines
909 B
Go
package logger
|
||
|
||
import (
|
||
"carrotskin/pkg/config"
|
||
"fmt"
|
||
"sync"
|
||
|
||
"go.uber.org/zap"
|
||
)
|
||
|
||
var (
|
||
// loggerInstance 全局日志实例
|
||
loggerInstance *zap.Logger
|
||
// once 确保只初始化一次
|
||
once sync.Once
|
||
// initError 初始化错误
|
||
initError error
|
||
)
|
||
|
||
// Init 初始化日志记录器(线程安全,只会执行一次)
|
||
func Init(cfg config.LogConfig) error {
|
||
once.Do(func() {
|
||
loggerInstance, initError = New(cfg)
|
||
if initError != nil {
|
||
return
|
||
}
|
||
})
|
||
return initError
|
||
}
|
||
|
||
// GetLogger 获取日志实例(线程安全)
|
||
func GetLogger() (*zap.Logger, error) {
|
||
if loggerInstance == nil {
|
||
return nil, fmt.Errorf("日志未初始化,请先调用 logger.Init()")
|
||
}
|
||
return loggerInstance, nil
|
||
}
|
||
|
||
// MustGetLogger 获取日志实例,如果未初始化则panic
|
||
func MustGetLogger() *zap.Logger {
|
||
logger, err := GetLogger()
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
return logger
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|