/
api.go
61 lines (54 loc) · 1.37 KB
/
api.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"github.com/suyuan32/simple-admin-common/orm/ent/mixins"
)
type API struct {
ent.Schema
}
func (API) Fields() []ent.Field {
return []ent.Field{
field.String("path").
Comment("API path | API 路径").
Annotations(entsql.WithComments(true)),
field.String("description").
Comment("API description | API 描述").
Annotations(entsql.WithComments(true)),
field.String("api_group").
Comment("API group | API 分组").
Annotations(entsql.WithComments(true)),
field.String("service_name").
Comment("Service name | 服务名称").
Default("Other").
Annotations(entsql.WithComments(true)),
field.String("method").Default("POST").
Comment("HTTP method | HTTP 请求类型").
Annotations(entsql.WithComments(true)),
field.Bool("is_required").Default(false).
Comment("Whether is required | 是否必选").
Annotations(entsql.WithComments(true)),
}
}
func (API) Mixin() []ent.Mixin {
return []ent.Mixin{
mixins.IDMixin{},
}
}
func (API) Edges() []ent.Edge {
return nil
}
func (API) Indexes() []ent.Index {
return []ent.Index{
index.Fields("path", "method").
Unique(),
}
}
func (API) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "sys_apis"},
}
}