github.com/infraboard/keyauth@v0.8.1/apps/application/request_ext.go (about) 1 package application 2 3 import ( 4 "errors" 5 6 "github.com/go-playground/validator/v10" 7 "github.com/infraboard/keyauth/apps/token" 8 "github.com/infraboard/mcube/http/request" 9 ) 10 11 // use a single instance of Validate, it caches struct info 12 var ( 13 validate = validator.New() 14 ) 15 16 // NewDescriptApplicationRequest new实例 17 func NewDescriptApplicationRequest() *DescribeApplicationRequest { 18 return &DescribeApplicationRequest{} 19 } 20 21 // Validate 校验详情查询请求 22 func (req *DescribeApplicationRequest) Validate() error { 23 if req.Id == "" && req.ClientId == "" { 24 return errors.New("application id or client_id is required") 25 } 26 27 return nil 28 } 29 30 // NewQueryApplicationRequest 列表查询请求 31 func NewQueryApplicationRequest(pageReq *request.PageRequest) *QueryApplicationRequest { 32 return &QueryApplicationRequest{ 33 Page: pageReq, 34 } 35 } 36 37 // NewCreateApplicatonRequest 请求 38 func NewCreateApplicatonRequest() *CreateApplicatonRequest { 39 return &CreateApplicatonRequest{ 40 AccessTokenExpireSecond: DefaultAccessTokenExpireSecond, 41 RefreshTokenExpireSecond: DefaultRefreshTokenExpiredSecond, 42 ClientType: ClientType_PUBLIC, 43 } 44 } 45 46 // Validate 请求校验 47 func (req *CreateApplicatonRequest) Validate() error { 48 return validate.Struct(req) 49 } 50 51 func (req *CreateApplicatonRequest) UpdateOwner(tk *token.Token) { 52 req.CreateBy = tk.Account 53 req.Domain = tk.Domain 54 } 55 56 // NewDeleteApplicationRequestWithID todo 57 func NewDeleteApplicationRequestWithID(id string) *DeleteApplicationRequest { 58 return &DeleteApplicationRequest{Id: id} 59 }