Skip to content

Commit 4d57765

Browse files
committed
code refactor
1 parent 04a218e commit 4d57765

File tree

10 files changed

+90
-102
lines changed

10 files changed

+90
-102
lines changed

conf/expr.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ import (
2222
"github.com/expr-lang/expr"
2323
)
2424

25-
type ValidateFunc[T interface{}] func(T) bool
25+
// ValidateFunc defines a type for validation functions, which accept
26+
// a value of type T and return a boolean result.
27+
type ValidateFunc[T any] func(T) bool
2628

29+
// validateFuncs holds a map of registered validation functions.
2730
var validateFuncs = map[string]interface{}{}
2831

29-
func RegisterValidateFunc[T interface{}](name string, fn ValidateFunc[T]) {
32+
// RegisterValidateFunc registers a validation function with a specific name.
33+
// The function can then be used in validation expressions.
34+
func RegisterValidateFunc[T any](name string, fn ValidateFunc[T]) {
3035
validateFuncs[name] = fn
3136
}
3237

33-
// validateField validates the field with the given tag and value.
38+
// validateField validates a field using a validation expression (tag) and the field value (i).
39+
// It evaluates the expression and checks if the result is true (i.e., the validation passes).
40+
// If any error occurs during evaluation or if the validation fails, an error is returned.
3441
func validateField(tag string, i interface{}) error {
3542
env := map[string]interface{}{"$": i}
3643
for k, v := range validateFuncs {

gs/gs.go

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ import (
3232
)
3333

3434
const (
35-
Version = "go-spring@v1.1.3"
35+
Version = "go-spring@v1.2.0.rc"
3636
Website = "https://go-spring.com/"
3737
)
3838

3939
/************************************ arg ***********************************/
4040

4141
type Arg = gs.Arg
4242

43-
// NilArg returns a ValueArg with a nil value.
44-
func NilArg() gs_arg.ValueArg {
45-
return gs_arg.Nil()
46-
}
47-
4843
// TagArg returns a TagArg with the specified tag.
4944
func TagArg(tag string) gs_arg.TagArg {
5045
return gs_arg.TagArg{Tag: tag}
5146
}
5247

48+
// NilArg returns a ValueArg with a nil value.
49+
func NilArg() gs_arg.ValueArg {
50+
return gs_arg.Nil()
51+
}
52+
5353
// ValueArg returns a ValueArg with the specified value.
5454
func ValueArg(v interface{}) gs_arg.ValueArg {
5555
return gs_arg.Value(v)
@@ -129,7 +129,7 @@ func Or(conditions ...Condition) Condition {
129129
return gs_cond.Or(conditions...)
130130
}
131131

132-
// And creates a Condition that is true if all of the given Conditions are true.
132+
// And creates a Condition that is true if all the given Conditions are true.
133133
func And(conditions ...Condition) Condition {
134134
return gs_cond.And(conditions...)
135135
}
@@ -146,36 +146,30 @@ func OnProfile(profile string) Condition {
146146

147147
/************************************ ioc ************************************/
148148

149-
type (
150-
BeanSelector = gs.BeanSelector
151-
)
152-
153-
type (
154-
Properties = gs.Properties
155-
)
156-
157149
type (
158150
Context = gs.Context
159151
ContextAware = gs.ContextAware
160152
)
161153

162154
type (
155+
Properties = gs.Properties
163156
Refreshable = gs.Refreshable
164157
Dync[T any] = gs_dync.Value[T]
165158
)
166159

167160
type (
161+
RegisteredBean = gs.RegisteredBean
162+
BeanDefinition = gs.BeanDefinition
163+
)
164+
165+
type (
166+
BeanSelector = gs.BeanSelector
168167
BeanInitFunc = gs.BeanInitFunc
169168
BeanDestroyFunc = gs.BeanDestroyFunc
170169
BeanInitInterface = gs.BeanInitInterface
171170
BeanDestroyInterface = gs.BeanDestroyInterface
172171
)
173172

174-
type (
175-
RegisteredBean = gs.RegisteredBean
176-
BeanDefinition = gs.BeanDefinition
177-
)
178-
179173
// NewBean creates a new BeanDefinition.
180174
var NewBean = gs_core.NewBean
181175

@@ -188,6 +182,14 @@ func BeanSelectorForType[T any]() BeanSelector {
188182

189183
var boot *gs_app.Boot
190184

185+
// Boot initializes and returns a [*gs_app.Boot] instance.
186+
func Boot() *gs_app.Boot {
187+
if boot == nil {
188+
boot = gs_app.NewBoot()
189+
}
190+
return boot
191+
}
192+
191193
// bootRun runs the boot process.
192194
func bootRun() error {
193195
if boot != nil {
@@ -199,14 +201,6 @@ func bootRun() error {
199201
return nil
200202
}
201203

202-
// Boot initializes and returns a [gs_app.Boot] instance.
203-
func Boot() *gs_app.Boot {
204-
if boot == nil {
205-
boot = gs_app.NewBoot()
206-
}
207-
return boot
208-
}
209-
210204
/*********************************** app *************************************/
211205

212206
type (
@@ -246,6 +240,11 @@ func Config() *gs_conf.AppConfig {
246240
return app.P
247241
}
248242

243+
// RefreshProperties refreshes the app configuration.
244+
func RefreshProperties(p Properties) error {
245+
return app.C.RefreshProperties(p)
246+
}
247+
249248
// Object registers a bean definition for a given object.
250249
func Object(i interface{}) *RegisteredBean {
251250
b := NewBean(reflect.ValueOf(i))
@@ -284,11 +283,6 @@ func Server(objOrCtor interface{}, ctorArgs ...Arg) *RegisteredBean {
284283
return app.C.Register(b)
285284
}
286285

287-
// RefreshProperties refreshes the app configuration.
288-
func RefreshProperties(p Properties) error {
289-
return app.C.RefreshProperties(p)
290-
}
291-
292286
/********************************** banner ***********************************/
293287

294288
var appBanner = `

gs/internal/gs_app/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
// Package gs_app provides a framework for building and managing Go-Spring applications.
1718
package gs_app
1819

1920
import (

0 commit comments

Comments
 (0)