package handler import ( "errors" "github.com/loveuer/nf" "github.com/loveuer/nf/nft/resp" "gorm.io/gorm" "uauth/internal/store/db" "uauth/internal/tool" "uauth/model" ) func ClientRegistry(c *nf.Ctx) error { type Req struct { ClientId string `json:"client_id"` Icon string `json:"icon"` // url Name string `json:"name"` } var ( err error req = new(Req) ) if err = c.BodyParser(req); err != nil { return resp.Resp400(c, err.Error()) } Secret := tool.RandomString(32) platform := &model.Platform{ ClientId: req.ClientId, Icon: req.Icon, Name: req.Name, ClientSecret: Secret, } if err = db.Default.Session().Create(platform).Error; err != nil { if errors.Is(err, gorm.ErrDuplicatedKey) { return resp.Resp400(c, err, "当前平台已经存在") } return resp.Resp500(c, err) } return resp.Resp200(c, platform) }