-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_namepattern_optiongen.go
179 lines (154 loc) · 6.28 KB
/
gen_namepattern_optiongen.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Code generated by optiongen. DO NOT EDIT.
// optiongen: github.com/timestee/optiongen
package protokit
import (
"sync/atomic"
"unsafe"
)
// NamePattern should use NewNamePattern to initialize it
type NamePattern struct {
// annotation@NamePatternServerHandler(comment="code server handler名称格式化")
NamePatternServerHandler string `xconf:"name_pattern_server_handler" usage:"code server handler名称格式化"`
// annotation@NamePatternRPCClient(comment="code rpc client名称格式化")
NamePatternRPCClient string `xconf:"name_pattern_rpc_client" usage:"code rpc client名称格式化"`
// annotation@NamePatternActorClient(comment="code actor client名称格式化")
NamePatternActorClient string `xconf:"name_pattern_actor_client" usage:"code actor client名称格式化"`
// annotation@NamePatternERPCClient(comment="code erpc client名称格式化")
NamePatternERPCClient string `xconf:"name_pattern_erpc_client" usage:"code erpc client名称格式化"`
// annotation@NamePatternHTTPPath(comment="自动生成的HTTP PATHG格式")
NamePatternHTTPPath string `xconf:"name_pattern_http_path" usage:"自动生成的HTTP PATHG格式"`
}
// NewNamePattern new NamePattern
func NewNamePattern(opts ...NamePatternOption) *NamePattern {
cc := newDefaultNamePattern()
for _, opt := range opts {
opt(cc)
}
if watchDogNamePattern != nil {
watchDogNamePattern(cc)
}
return cc
}
// ApplyOption apply multiple new option and return the old ones
// sample:
// old := cc.ApplyOption(WithTimeout(time.Second))
// defer cc.ApplyOption(old...)
func (cc *NamePattern) ApplyOption(opts ...NamePatternOption) []NamePatternOption {
var previous []NamePatternOption
for _, opt := range opts {
previous = append(previous, opt(cc))
}
return previous
}
// NamePatternOption option func
type NamePatternOption func(cc *NamePattern) NamePatternOption
// WithNamePatternServerHandler code server handler名称格式化
func WithNamePatternServerHandler(v string) NamePatternOption {
return func(cc *NamePattern) NamePatternOption {
previous := cc.NamePatternServerHandler
cc.NamePatternServerHandler = v
return WithNamePatternServerHandler(previous)
}
}
// WithNamePatternRPCClient code rpc client名称格式化
func WithNamePatternRPCClient(v string) NamePatternOption {
return func(cc *NamePattern) NamePatternOption {
previous := cc.NamePatternRPCClient
cc.NamePatternRPCClient = v
return WithNamePatternRPCClient(previous)
}
}
// WithNamePatternActorClient code actor client名称格式化
func WithNamePatternActorClient(v string) NamePatternOption {
return func(cc *NamePattern) NamePatternOption {
previous := cc.NamePatternActorClient
cc.NamePatternActorClient = v
return WithNamePatternActorClient(previous)
}
}
// WithNamePatternERPCClient code erpc client名称格式化
func WithNamePatternERPCClient(v string) NamePatternOption {
return func(cc *NamePattern) NamePatternOption {
previous := cc.NamePatternERPCClient
cc.NamePatternERPCClient = v
return WithNamePatternERPCClient(previous)
}
}
// WithNamePatternHTTPPath 自动生成的HTTP PATHG格式
func WithNamePatternHTTPPath(v string) NamePatternOption {
return func(cc *NamePattern) NamePatternOption {
previous := cc.NamePatternHTTPPath
cc.NamePatternHTTPPath = v
return WithNamePatternHTTPPath(previous)
}
}
// InstallNamePatternWatchDog the installed func will called when NewNamePattern called
func InstallNamePatternWatchDog(dog func(cc *NamePattern)) { watchDogNamePattern = dog }
// watchDogNamePattern global watch dog
var watchDogNamePattern func(cc *NamePattern)
// newDefaultNamePattern new default NamePattern
func newDefaultNamePattern() *NamePattern {
cc := &NamePattern{}
for _, opt := range [...]NamePatternOption{
WithNamePatternServerHandler("ServerHandler%s"),
WithNamePatternRPCClient("RPCClient%s"),
WithNamePatternActorClient("ActorClient%s"),
WithNamePatternERPCClient("ERPCClient%s"),
WithNamePatternHTTPPath("%s"),
} {
opt(cc)
}
return cc
}
// AtomicSetFunc used for XConf
func (cc *NamePattern) AtomicSetFunc() func(interface{}) { return AtomicNamePatternSet }
// atomicNamePattern global *NamePattern holder
var atomicNamePattern unsafe.Pointer
// onAtomicNamePatternSet global call back when AtomicNamePatternSet called by XConf.
// use NamePatternInterface.ApplyOption to modify the updated cc
// if passed in cc not valid, then return false, cc will not set to atomicNamePattern
var onAtomicNamePatternSet func(cc NamePatternInterface) bool
// InstallCallbackOnAtomicNamePatternSet install callback
func InstallCallbackOnAtomicNamePatternSet(callback func(cc NamePatternInterface) bool) {
onAtomicNamePatternSet = callback
}
// AtomicNamePatternSet atomic setter for *NamePattern
func AtomicNamePatternSet(update interface{}) {
cc := update.(*NamePattern)
if onAtomicNamePatternSet != nil && !onAtomicNamePatternSet(cc) {
return
}
atomic.StorePointer(&atomicNamePattern, (unsafe.Pointer)(cc))
}
// AtomicNamePattern return atomic *NamePatternVisitor
func AtomicNamePattern() NamePatternVisitor {
current := (*NamePattern)(atomic.LoadPointer(&atomicNamePattern))
if current == nil {
defaultOne := newDefaultNamePattern()
if watchDogNamePattern != nil {
watchDogNamePattern(defaultOne)
}
atomic.CompareAndSwapPointer(&atomicNamePattern, nil, (unsafe.Pointer)(defaultOne))
return (*NamePattern)(atomic.LoadPointer(&atomicNamePattern))
}
return current
}
// all getter func
func (cc *NamePattern) GetNamePatternServerHandler() string { return cc.NamePatternServerHandler }
func (cc *NamePattern) GetNamePatternRPCClient() string { return cc.NamePatternRPCClient }
func (cc *NamePattern) GetNamePatternActorClient() string { return cc.NamePatternActorClient }
func (cc *NamePattern) GetNamePatternERPCClient() string { return cc.NamePatternERPCClient }
func (cc *NamePattern) GetNamePatternHTTPPath() string { return cc.NamePatternHTTPPath }
// NamePatternVisitor visitor interface for NamePattern
type NamePatternVisitor interface {
GetNamePatternServerHandler() string
GetNamePatternRPCClient() string
GetNamePatternActorClient() string
GetNamePatternERPCClient() string
GetNamePatternHTTPPath() string
}
// NamePatternInterface visitor + ApplyOption interface for NamePattern
type NamePatternInterface interface {
NamePatternVisitor
ApplyOption(...NamePatternOption) []NamePatternOption
}