-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_endpoint.go
43 lines (38 loc) · 1.34 KB
/
model_endpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package goacl
import (
"github.com/uptrace/bun"
)
type Endpoint struct {
bun.BaseModel `bun:"table:endpoints,alias:enp"`
ID int64 `bun:"id,pk,autoincrement" json:"id"`
Method string `bun:"method" json:"method"`
URL string `bun:"url" json:"url"`
SubFeatureID int64 `bun:"sub_feature_id" json:"sub_feature_id"`
SubFeature *SubFeature `bun:"rel:belongs-to,join:sub_feature_id=id" json:"sub_feature,omitempty"`
}
type EndpointParam struct {
ID int64 `param:"id" query:"id" form:"id" json:"id" xml:"id"`
Method string `param:"method" query:"method" form:"method" json:"method" xml:"method" validate:"required"`
URL string `param:"url" query:"url" form:"url" json:"url" xml:"url" validate:"required"`
SubFeatureID int64 `param:"sub_feature_id" query:"sub_feature_id" form:"sub_feature_id" json:"sub_feature_id" xml:"sub_feature_id" validate:"required"`
}
// func (p *EndpointParam) Validate() error {
// validate := validator.New()
// err := validate.Struct(p)
// if err != nil {
// return err
// }
// return nil
// }
func (p *EndpointParam) ValidateForUpdate(data *Endpoint) (*Endpoint, error) {
if p.URL != "" {
data.URL = p.URL
}
if p.Method != "" {
data.Method = p.Method
}
if p.SubFeatureID != 0 {
data.SubFeatureID = p.SubFeatureID
}
return data, nil
}