-
Notifications
You must be signed in to change notification settings - Fork 39
/
setting.go
86 lines (79 loc) · 1.98 KB
/
setting.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"github.com/seal-io/walrus/pkg/dao/entx"
"github.com/seal-io/walrus/pkg/dao/schema/mixin"
"github.com/seal-io/walrus/pkg/dao/types/crypto"
)
type Setting struct {
ent.Schema
}
func (Setting) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.ID(),
mixin.Time(),
}
}
func (Setting) Indexes() []ent.Index {
return []ent.Index{
index.Fields("name").
Unique(),
}
}
func (Setting) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Comment("The name of system setting.").
NotEmpty().
Immutable().
Annotations(
entx.SkipInput(
entx.WithCreate(),
entx.WithUpdate())),
crypto.StringField("value").
Comment("The value of system setting, store in string.").
StructTag(`json:"value,omitempty,cli-table-column"`),
field.Bool("hidden").
Comment("Indicate the system setting should be hidden or not, default is visible.").
Nillable().
Optional().
Default(false).
Annotations(
entx.SkipInput()),
field.Bool("editable").
Comment("Indicate the system setting should be edited or not, default is readonly.").
Nillable().
Optional().
Default(false).
Annotations(
entx.SkipInput()),
field.Bool("sensitive").
Comment("Indicate the system setting should be sanitized or not before exposing, default is not.").
Nillable().
Optional().
Default(false).
Annotations(
entx.SkipInput()),
field.Bool("private").
Comment("Indicate the system setting should be exposed or not, default is exposed.").
Nillable().
Optional().
Default(false).
Annotations(
entx.SkipIO()),
field.Bool("configured").
Comment("Configured indicates the setting whether to be configured.").
Optional().
Annotations(
entx.SkipInput(),
entx.SkipStoringField()),
}
}
func (Setting) Annotations() []schema.Annotation {
return []schema.Annotation{
entx.SkipClearingOptionalField(),
}
}