package utils import ( "fmt" "gitee.ltd/lxh/logger/log" "math/rand" "time" "wireguard-ui/global/client" ) type avatar struct{} func Avatar() avatar { return avatar{} } // GenerateAvatar // @description: 生成随机头像 - 默认头像 // @receiver avatar // @return path // @return err func (avatar) GenerateAvatar(isUpload bool) (path string, err error) { rand.New(rand.NewSource(time.Now().UnixNano())) r := client.HttpClient.R() result, err := r.Get(fmt.Sprintf("https://api.dicebear.com/7.x/croodles/png?seed=%d&scale=120&size=200&clip=true&randomizeIds=true&beard=variant01,variant02,variant03&"+ "eyes=variant01,variant02,variant03,variant04,variant05,variant06,variant07,variant08,variant09,variant10,variant11,variant12&mustache=variant01,variant02,variant03&"+ "topColor=000000,0fa958,699bf7", rand.Uint32())) if err != nil { log.Errorf("请求头像API失败: %v", err.Error()) return "", err } if isUpload { path, err = FileSystem().UploadFile(result.Body(), ".png") if err != nil { return "", err } return } return string(result.Body()), nil }