mirror of
https://github.com/gone-io/gone.git
synced 2025-01-23 01:00:23 +08:00
feat: fix gone.IsDefault error; check examples
This commit is contained in:
parent
9e86da37ea
commit
c0a5380829
102
cemetery.go
102
cemetery.go
@ -33,32 +33,30 @@ func GetGoneDefaultId(goner Goner) GonerId {
|
||||
}
|
||||
|
||||
func (c *cemetery) bury(goner Goner, options ...GonerOption) Tomb {
|
||||
t := NewTomb(goner)
|
||||
var id GonerId
|
||||
theTomb := NewTomb(goner)
|
||||
|
||||
for _, option := range options {
|
||||
switch option.(type) {
|
||||
case GonerId:
|
||||
id = option.(GonerId)
|
||||
case IsDefault:
|
||||
t.SetDefault(bool(option.(IsDefault)))
|
||||
theTomb.SetId(option.(GonerId))
|
||||
case defaultType:
|
||||
theTomb.SetDefault(option.(defaultType).t)
|
||||
case Order:
|
||||
t.SetOrder(option.(Order))
|
||||
theTomb.SetOrder(option.(Order))
|
||||
}
|
||||
}
|
||||
|
||||
if id == "" {
|
||||
id = GetGoneDefaultId(goner)
|
||||
if theTomb.GetId() == "" {
|
||||
theTomb.SetId(GetGoneDefaultId(goner))
|
||||
}
|
||||
|
||||
_, ok := c.tombMap[id]
|
||||
_, ok := c.tombMap[theTomb.GetId()]
|
||||
if ok {
|
||||
panic(GonerIdIsExistedError(id))
|
||||
panic(GonerIdIsExistedError(theTomb.GetId()))
|
||||
}
|
||||
|
||||
c.tombMap[id] = t.SetId(id)
|
||||
c.tombs = append(c.tombs, t)
|
||||
return t
|
||||
c.tombMap[theTomb.GetId()] = theTomb
|
||||
c.tombs = append(c.tombs, theTomb)
|
||||
return theTomb
|
||||
}
|
||||
|
||||
func (c *cemetery) Bury(goner Goner, options ...GonerOption) Cemetery {
|
||||
@ -68,11 +66,12 @@ func (c *cemetery) Bury(goner Goner, options ...GonerOption) Cemetery {
|
||||
|
||||
func (c *cemetery) filterGonerIdFromOptions(options []GonerOption) GonerId {
|
||||
var id GonerId
|
||||
|
||||
loop:
|
||||
for _, option := range options {
|
||||
switch option.(type) {
|
||||
case GonerId:
|
||||
id = option.(GonerId)
|
||||
break loop
|
||||
}
|
||||
}
|
||||
return id
|
||||
@ -91,17 +90,26 @@ func (c *cemetery) BuryOnce(goner Goner, options ...GonerOption) Cemetery {
|
||||
}
|
||||
|
||||
func (c *cemetery) ReplaceBury(goner Goner, options ...GonerOption) (err error) {
|
||||
var id = c.filterGonerIdFromOptions(options)
|
||||
if id == "" {
|
||||
newTomb := NewTomb(goner)
|
||||
|
||||
for _, option := range options {
|
||||
switch option.(type) {
|
||||
case GonerId:
|
||||
newTomb.SetId(option.(GonerId))
|
||||
case defaultType:
|
||||
newTomb.SetDefault(option.(defaultType).t)
|
||||
case Order:
|
||||
newTomb.SetOrder(option.(Order))
|
||||
}
|
||||
}
|
||||
if newTomb.GetId() == "" {
|
||||
err = ReplaceBuryIdParamEmptyError()
|
||||
return
|
||||
}
|
||||
|
||||
oldTomb := c.tombMap[id]
|
||||
replaceTomb := NewTomb(goner).SetId(id)
|
||||
c.tombMap[id] = replaceTomb
|
||||
oldTomb, buried := c.tombMap[newTomb.GetId()]
|
||||
c.tombMap[newTomb.GetId()] = newTomb
|
||||
|
||||
buried := oldTomb != nil
|
||||
var oldGoner Goner
|
||||
if buried {
|
||||
oldGoner = oldTomb.GetGoner()
|
||||
@ -113,12 +121,12 @@ func (c *cemetery) ReplaceBury(goner Goner, options ...GonerOption) (err error)
|
||||
}
|
||||
}
|
||||
|
||||
c.tombs = append(c.tombs, replaceTomb)
|
||||
_, err = c.reviveOneFromTomb(replaceTomb)
|
||||
c.tombs = append(c.tombs, newTomb)
|
||||
_, err = c.reviveOneFromTomb(newTomb)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.replaceTombsGonerField(id, goner, oldGoner, buried)
|
||||
return c.replaceTombsGonerField(newTomb.GetId(), goner, oldGoner, buried)
|
||||
}
|
||||
|
||||
func (c *cemetery) replaceTombsGonerField(id GonerId, newGoner, oldGoner Goner, buried bool) error {
|
||||
@ -252,7 +260,7 @@ func (c *cemetery) reviveSpecialTypeFields(field reflect.StructField, v reflect.
|
||||
t := field.Type
|
||||
switch t.Kind() {
|
||||
|
||||
case reflect.Slice: //允许注入接口切片
|
||||
case reflect.Slice: //support inject slice
|
||||
tombs := c.GetTomByType(t.Elem())
|
||||
for _, tomb := range tombs {
|
||||
if t.Elem().Kind() == reflect.Struct {
|
||||
@ -264,8 +272,8 @@ func (c *cemetery) reviveSpecialTypeFields(field reflect.StructField, v reflect.
|
||||
}
|
||||
suc = true
|
||||
|
||||
case reflect.Map: //允许注入接口Map
|
||||
if t.Key().Kind() == reflect.String { //Map的key是string类型
|
||||
case reflect.Map: //support inject map
|
||||
if t.Key().Kind() == reflect.String { //key of map must be string
|
||||
tombs := c.GetTomByType(t.Elem())
|
||||
|
||||
m := reflect.MakeMap(t)
|
||||
@ -346,7 +354,7 @@ func (c *cemetery) ReviveOne(goner any) (deps []Tomb, err error) {
|
||||
v = BlackMagic(v)
|
||||
}
|
||||
|
||||
//如果已经存在值,不再注入
|
||||
//do not inject multiple times
|
||||
if !v.IsZero() {
|
||||
continue
|
||||
}
|
||||
@ -354,7 +362,7 @@ func (c *cemetery) ReviveOne(goner any) (deps []Tomb, err error) {
|
||||
var suc bool
|
||||
var tmpDeps []Tomb
|
||||
|
||||
// 根据Id匹配
|
||||
// inject by id
|
||||
if tmpDeps, suc, err = c.reviveFieldById(tag, field, v); err != nil {
|
||||
return
|
||||
} else if suc {
|
||||
@ -362,13 +370,13 @@ func (c *cemetery) ReviveOne(goner any) (deps []Tomb, err error) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 根据类型匹配
|
||||
// inject by type
|
||||
if tmpDeps, suc = c.reviveFieldByType(field, v, goneTypeName); suc {
|
||||
deps = append(deps, tmpDeps...)
|
||||
continue
|
||||
}
|
||||
|
||||
// 特殊类型处理
|
||||
// inject special types
|
||||
if tmpDeps, suc = c.reviveSpecialTypeFields(field, v); suc {
|
||||
deps = append(deps, tmpDeps...)
|
||||
continue
|
||||
@ -406,26 +414,24 @@ var obsessionType = reflect.TypeOf(obsessionPtr).Elem()
|
||||
var obsessionPtr2 *Prophet2
|
||||
var obsessionType2 = reflect.TypeOf(obsessionPtr2).Elem()
|
||||
|
||||
func (c *cemetery) prophesy() error {
|
||||
var tombs = c.GetTomByType(obsessionType)
|
||||
func (c *cemetery) prophesy() (err error) {
|
||||
var tombs Tombs = c.GetTomByType(obsessionType)
|
||||
tombs = append(tombs, c.GetTomByType(obsessionType2)...)
|
||||
sort.Sort(tombs)
|
||||
|
||||
for _, tomb := range tombs {
|
||||
obsession := tomb.GetGoner().(Prophet)
|
||||
err := obsession.AfterRevive()
|
||||
goner := tomb.GetGoner()
|
||||
switch goner.(type) {
|
||||
case Prophet:
|
||||
err = goner.(Prophet).AfterRevive()
|
||||
case Prophet2:
|
||||
err = goner.(Prophet2).AfterRevive()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
tombs = c.GetTomByType(obsessionType2)
|
||||
for _, tomb := range tombs {
|
||||
obsession := tomb.GetGoner().(Prophet2)
|
||||
err := obsession.AfterRevive()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -442,9 +448,9 @@ func (c *cemetery) getGonerContainerByType(t reflect.Type, name string) Tomb {
|
||||
if len(tombs) > 0 {
|
||||
var container Tomb
|
||||
|
||||
for _, t := range tombs {
|
||||
if t.IsDefault() {
|
||||
container = t
|
||||
for _, tmp := range tombs {
|
||||
if tmp.IsDefault(t) {
|
||||
container = tmp
|
||||
break
|
||||
}
|
||||
}
|
||||
|
4
error.go
4
error.go
@ -31,7 +31,7 @@ type defaultErr struct {
|
||||
}
|
||||
|
||||
func (e *defaultErr) Error() string {
|
||||
return fmt.Sprintf("GoneError(code=%v):%s", e.Code(), e.Msg())
|
||||
return fmt.Sprintf("GoneError(code=%v); %s", e.Code(), e.Msg())
|
||||
}
|
||||
|
||||
func (e *defaultErr) Msg() string {
|
||||
@ -96,7 +96,7 @@ type iError struct {
|
||||
|
||||
func (e *iError) Error() string {
|
||||
msg := e.defaultErr.Error()
|
||||
return fmt.Sprintf("%s\n%s", msg, e.trace)
|
||||
return fmt.Sprintf("%s\n\n%s", msg, e.trace)
|
||||
}
|
||||
|
||||
func (e *iError) Stack() []byte {
|
||||
|
@ -73,7 +73,7 @@ func TestNewBusinessError(t *testing.T) {
|
||||
assert.Equal(t, "error", businessError.Msg())
|
||||
assert.Equal(t, 100, businessError.Code())
|
||||
assert.Equal(t, data, businessError.Data())
|
||||
assert.Equal(t, "GoneError(code=100):error", businessError.Error())
|
||||
assert.Equal(t, "GoneError(code=100); error", businessError.Error())
|
||||
}
|
||||
|
||||
func TestNewParameterError(t *testing.T) {
|
||||
|
@ -20,7 +20,7 @@ func (c *Computer) Compute() {
|
||||
println("1000 add 2000 is", c.adder.Add(1000, 2000))
|
||||
}
|
||||
|
||||
// AfterRevive 复活后执行的函数
|
||||
// AfterRevive will execute after revive
|
||||
func (c *Computer) AfterRevive() gone.AfterReviveError {
|
||||
// boot
|
||||
c.Compute()
|
||||
|
@ -5,7 +5,7 @@ go 1.21
|
||||
toolchain go1.21.1
|
||||
|
||||
require (
|
||||
github.com/gone-io/gone v0.0.0-20221018135039-2d9d20647331
|
||||
github.com/gone-io/gone v1.0.2
|
||||
github.com/stretchr/testify v1.9.0
|
||||
)
|
||||
|
||||
@ -55,18 +55,23 @@ require (
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.20.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
google.golang.org/grpc v1.63.2 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v0.0.0-20221018135039-2d9d20647331 => ../../
|
||||
replace github.com/gone-io/gone v1.0.2 => ../../
|
||||
|
@ -2,4 +2,40 @@ module gen-code
|
||||
|
||||
go 1.21.1
|
||||
|
||||
require github.com/gone-io/gone v0.1.1
|
||||
require github.com/gone-io/gone v1.0.2
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.10.2 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/gin-gonic/gin v1.9.1 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.17.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/leodido/go-urn v1.3.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/soheilhy/cmux v0.1.5 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v1.0.2 => ../../
|
||||
|
@ -30,7 +30,7 @@ func (c *Computer) Compute() {
|
||||
println("1000 add 2000 is", c.adder.Add(1000, 2000))
|
||||
}
|
||||
|
||||
// AfterRevive 复活后执行的函数
|
||||
// AfterRevive will execute after revive
|
||||
func (c *Computer) AfterRevive() gone.AfterReviveError {
|
||||
// boot
|
||||
c.Compute()
|
||||
|
@ -3,7 +3,8 @@ module example
|
||||
go 1.21.1
|
||||
|
||||
require (
|
||||
github.com/gone-io/gone v0.3.1
|
||||
github.com/golang/mock v1.6.0
|
||||
github.com/gone-io/gone v1.0.2
|
||||
github.com/stretchr/testify v1.9.0
|
||||
)
|
||||
|
||||
@ -11,7 +12,7 @@ require (
|
||||
github.com/bytedance/sonic v1.10.2 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/gin-gonic/gin v1.9.1 // indirect
|
||||
@ -19,33 +20,30 @@ require (
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.17.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||
github.com/google/go-cmp v0.5.6 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/jtolds/gls v4.20.0+incompatible // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/leodido/go-urn v1.3.0 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/soheilhy/cmux v0.1.5 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.20.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v1.0.2 => ../
|
||||
|
@ -55,8 +55,9 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
@ -120,8 +121,6 @@ github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8l
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/gone-io/gone v0.3.1 h1:Zn48lTtCNmwf5+YypFLWaeNKO/+DRT87PNKb77ioYCs=
|
||||
github.com/gone-io/gone v0.3.1/go.mod h1:L1yrG6dslIactxINce1afQIFPH3+hxDGPDXweyn0SL0=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
@ -137,8 +136,6 @@ github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
|
||||
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
|
||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
@ -225,7 +222,6 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
|
||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||
@ -255,8 +251,8 @@ github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
||||
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
||||
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
@ -317,16 +313,17 @@ github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnh
|
||||
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
|
||||
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
|
||||
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||
@ -364,11 +361,11 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js=
|
||||
github.com/soheilhy/cmux v0.1.5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0=
|
||||
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
@ -380,6 +377,7 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
@ -470,6 +468,7 @@ golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
|
||||
@ -515,11 +514,10 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
@ -3,7 +3,7 @@ module grpc
|
||||
go 1.22.2
|
||||
|
||||
require (
|
||||
github.com/gone-io/gone v0.3.1
|
||||
github.com/gone-io/gone v1.0.2
|
||||
google.golang.org/grpc v1.64.0
|
||||
google.golang.org/protobuf v1.34.1
|
||||
)
|
||||
@ -52,19 +52,21 @@ require (
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.20.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v0.3.1 => ../../
|
||||
replace github.com/gone-io/gone v1.0.2 => ../../
|
||||
|
@ -1,2 +1,2 @@
|
||||
server.port=9090
|
||||
server.mode=
|
||||
server.mode=release
|
@ -4,7 +4,7 @@ go 1.21
|
||||
|
||||
toolchain go1.21.1
|
||||
|
||||
require github.com/gone-io/gone v0.0.4
|
||||
require github.com/gone-io/gone v1.0.2
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||
@ -50,18 +50,23 @@ require (
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.20.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
google.golang.org/grpc v1.63.2 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v0.0.4 => ../../
|
||||
replace github.com/gone-io/gone v1.0.2 => ../../
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/gone-io/gone"
|
||||
"github.com/gone-io/gone/goner/gin"
|
||||
"github.com/gone-io/gone/goner/logrus"
|
||||
)
|
||||
|
||||
//go:gone
|
||||
@ -26,20 +25,15 @@ func (ctr *user) Mount() gin.MountError {
|
||||
|
||||
ctr.pub.
|
||||
GET("/test", func(in struct {
|
||||
page string `gone:"http,query=page"`
|
||||
cookX string `gone:"http,cookie=x"`
|
||||
headerY string `gone:"http,header=y"`
|
||||
token string `gone:"http,auth=Bearer"`
|
||||
formData string `gone:"http,form=data"`
|
||||
page string `gone:"http,query=page"`
|
||||
cookX string `gone:"http,cookie=x"`
|
||||
headerY string `gone:"http,header=y"`
|
||||
|
||||
host string `gone:"http,host"`
|
||||
url string `gone:"http,url"`
|
||||
path string `gone:"http,path"`
|
||||
query map[string]string `gone:"http,query"`
|
||||
data string `gone:"http,body"`
|
||||
context *gin.Context `gone:"http,context"`
|
||||
context *gin.Context `gone:"http,x"`
|
||||
|
||||
log logrus.Logger `gone:"gone-logger"`
|
||||
log gone.Logger `gone:"gone-logger"`
|
||||
}) string {
|
||||
|
||||
fmt.Printf("%v", in)
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
func Test_Line(t *testing.T) {
|
||||
t.Run("config default", func(t *testing.T) {
|
||||
gone.TestAt(pointNameA, func(point *Point) {
|
||||
assert.Equal(t, point.X, 1000)
|
||||
assert.Equal(t, point.X, 0)
|
||||
assert.Equal(t, point.Y, 200)
|
||||
}, config.Priest, Priest)
|
||||
})
|
||||
@ -28,7 +28,7 @@ func Test_Line(t *testing.T) {
|
||||
Mock := func() gone.Goner {
|
||||
return &Point{X: 20}
|
||||
}
|
||||
return cemetery.ReplaceBury(Mock(), pointNameA)
|
||||
return cemetery.ReplaceBury(Mock(), gone.GonerId(pointNameA))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -2,15 +2,42 @@ module use-config
|
||||
|
||||
go 1.21.1
|
||||
|
||||
require github.com/gone-io/gone v0.1.4
|
||||
require github.com/gone-io/gone v1.0.2
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||
github.com/jtolds/gls v4.20.0+incompatible // indirect
|
||||
github.com/bytedance/sonic v1.10.2 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/gin-gonic/gin v1.9.1 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.17.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/go-cmp v0.5.6 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/leodido/go-urn v1.3.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/soheilhy/cmux v0.1.5 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v0.1.4 => ../..
|
||||
replace github.com/gone-io/gone v1.0.2 => ../..
|
||||
|
@ -16,8 +16,8 @@ type Boss struct {
|
||||
func main() {
|
||||
gone.
|
||||
Prepare(func(cemetery gone.Cemetery) error {
|
||||
cemetery.Bury(&Boss{Name: "Jim"}, "boss-jim")
|
||||
cemetery.Bury(&Worker{Name: "Bob"}, "worker-bob")
|
||||
cemetery.Bury(&Boss{Name: "Jim"}, gone.GonerId("boss-jim"))
|
||||
cemetery.Bury(&Worker{Name: "Bob"}, gone.GonerId("worker-bob"))
|
||||
return nil
|
||||
}).
|
||||
BeforeStart(func() {
|
||||
|
@ -4,7 +4,7 @@ go 1.21.1
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/gone-io/gone v0.1.5
|
||||
github.com/gone-io/gone v1.0.2
|
||||
)
|
||||
|
||||
require (
|
||||
@ -51,18 +51,23 @@ require (
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.20.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
google.golang.org/grpc v1.63.2 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v0.1.5 => ../..
|
||||
replace github.com/gone-io/gone v1.0.2 => ../..
|
||||
|
@ -2,37 +2,69 @@ module use-redis
|
||||
|
||||
go 1.21.1
|
||||
|
||||
require github.com/gone-io/gone v0.3.1
|
||||
require github.com/gone-io/gone v1.0.2
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||
github.com/bytedance/sonic v1.10.2 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||
github.com/cloudflare/circl v1.3.8 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/gin-gonic/gin v1.9.1 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.17.0 // indirect
|
||||
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/gomodule/redigo v1.8.9 // indirect
|
||||
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/imroc/req/v3 v3.43.3 // indirect
|
||||
github.com/jmoiron/sqlx v1.3.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/jtolds/gls v4.20.0+incompatible // indirect
|
||||
github.com/klauspost/compress v1.17.8 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/leodido/go-urn v1.3.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||
github.com/onsi/ginkgo/v2 v2.17.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/quic-go/qpack v0.4.0 // indirect
|
||||
github.com/quic-go/quic-go v0.43.0 // indirect
|
||||
github.com/refraction-networking/utls v1.6.4 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/soheilhy/cmux v0.1.5 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.20.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
google.golang.org/grpc v1.63.2 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v1.0.2 => ../..
|
||||
|
@ -47,10 +47,10 @@ func (r *redisUser) UseCache() {
|
||||
&getValue, //第二参数为指针,接收获取缓存的值,类型为any,可以是任意类型;从redis获取的值会被解码为传入的指针类型
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Printf("err:%v", err)
|
||||
fmt.Printf("err: %v", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("getValue:%v", getValue)
|
||||
fmt.Printf("getValue: %v", getValue)
|
||||
}
|
||||
|
||||
func (r *redisUser) LockTime() {
|
||||
|
7
example/use-redis/redis.docker-compose.yaml
Normal file
7
example/use-redis/redis.docker-compose.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
services:
|
||||
redis:
|
||||
image: redis:7.2.5-alpine
|
||||
volumes:
|
||||
- ./data:/data
|
||||
ports:
|
||||
- 6379:6379
|
@ -2,7 +2,7 @@ module use-redis
|
||||
|
||||
go 1.21.1
|
||||
|
||||
require github.com/gone-io/gone v0.3.1
|
||||
require github.com/gone-io/gone v1.0.2
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||
@ -32,12 +32,12 @@ require (
|
||||
github.com/klauspost/compress v1.17.8 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/leodido/go-urn v1.3.0 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/onsi/ginkgo/v2 v2.17.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/quic-go/qpack v0.4.0 // indirect
|
||||
github.com/quic-go/quic-go v0.43.0 // indirect
|
||||
github.com/refraction-networking/utls v1.6.4 // indirect
|
||||
@ -48,16 +48,23 @@ require (
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.20.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
google.golang.org/grpc v1.63.2 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v1.0.2 => ../..
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/gone-io/gone/goner"
|
||||
"github.com/gone-io/gone/goner/config"
|
||||
"github.com/gone-io/gone/goner/schedule"
|
||||
"time"
|
||||
)
|
||||
|
||||
func priest(cemetery gone.Cemetery) error {
|
||||
@ -28,7 +29,7 @@ type sch struct {
|
||||
|
||||
func (sch *sch) job1() {
|
||||
//todo 定时任务逻辑
|
||||
fmt.Println("job1 execute")
|
||||
fmt.Printf("%v => job1 execute\n", time.Now())
|
||||
}
|
||||
|
||||
func (sch *sch) Cron(run schedule.RunFuncOnceAt) {
|
||||
|
7
example/use-schedule/redis.docker-compose.yaml
Normal file
7
example/use-schedule/redis.docker-compose.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
services:
|
||||
redis:
|
||||
image: redis:7.2.5-alpine
|
||||
volumes:
|
||||
- ./data:/data
|
||||
ports:
|
||||
- 6379:6379
|
@ -6,7 +6,7 @@ toolchain go1.21.1
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/gone-io/gone v0.3.0
|
||||
github.com/gone-io/gone v1.0.1
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
)
|
||||
|
||||
@ -53,20 +53,23 @@ require (
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
go.uber.org/mock v0.4.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.20.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
google.golang.org/grpc v1.63.2 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v0.3.0 => ../..
|
||||
replace github.com/gone-io/gone v1.0.1 => ../..
|
||||
|
@ -4,7 +4,7 @@ go 1.21
|
||||
|
||||
toolchain go1.21.1
|
||||
|
||||
require github.com/gone-io/gone v0.1.0
|
||||
require github.com/gone-io/gone v1.0.2
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||
@ -57,7 +57,7 @@ require (
|
||||
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.20.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
@ -69,4 +69,4 @@ require (
|
||||
xorm.io/xorm v1.3.2 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gone-io/gone v0.1.0 => ../../
|
||||
replace github.com/gone-io/gone v1.0.2 => ../../
|
||||
|
@ -1,42 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gone-io/gone"
|
||||
)
|
||||
|
||||
type Worker struct {
|
||||
gone.Flag // Goner标志,匿名内嵌`gone.Flag`表示该结构体为一个Goner
|
||||
}
|
||||
|
||||
func (w *Worker) Do() {
|
||||
fmt.Println("worker do")
|
||||
}
|
||||
|
||||
type Boss struct {
|
||||
gone.Flag // Goner标志,匿名内嵌`gone.Flag`表示该结构体为一个Goner
|
||||
|
||||
seller *Worker `gone:"*"` //注入Worker
|
||||
}
|
||||
|
||||
func (b *Boss) Do() {
|
||||
fmt.Println("boss do")
|
||||
b.seller.Do()
|
||||
}
|
||||
|
||||
func main() {
|
||||
gone.
|
||||
Prepare(func(cemetery gone.Cemetery) error {
|
||||
cemetery.
|
||||
Bury(&Boss{}).
|
||||
Bury(&Worker{})
|
||||
return nil
|
||||
}).
|
||||
//AfterStart 是一个hook函数,关于hook函数请参考文档:https://goner.fun/zh/guide/hooks.html
|
||||
AfterStart(func(in struct {
|
||||
boss *Boss `gone:"*"` //注入Boss
|
||||
}) {
|
||||
in.boss.Do()
|
||||
}).
|
||||
Run()
|
||||
}
|
2
go.mod
2
go.mod
@ -85,7 +85,7 @@ require (
|
||||
golang.org/x/mod v0.17.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -605,8 +605,8 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
func NewServer() (gone.Angel, gone.GonerId, gone.GonerOption, gone.GonerOption) {
|
||||
s := server{}
|
||||
s.listen = net.Listen
|
||||
return &s, gone.IdGoneCMux, gone.IsDefault(true), gone.Order1
|
||||
return &s, gone.IdGoneCMux, gone.IsDefault(new(gone.CMuxServer)), gone.Order1
|
||||
}
|
||||
|
||||
type server struct {
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
|
||||
type Configure = gone.Configure
|
||||
|
||||
func NewConfig() (gone.Vampire, gone.GonerId, gone.GonerOption, gone.GonerOption) {
|
||||
return &config{}, gone.IdConfig, gone.IsDefault(true), gone.Order0
|
||||
func NewConfig() (gone.Vampire, gone.GonerId, gone.GonerOption) {
|
||||
return &config{}, gone.IdConfig, gone.Order0
|
||||
}
|
||||
|
||||
type config struct {
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func NewConfigure() (gone.Goner, gone.GonerId, gone.GonerOption, gone.GonerOption) {
|
||||
return &configure{}, gone.IdGoneConfigure, gone.IsDefault(true), gone.Order0
|
||||
return &configure{}, gone.IdGoneConfigure, gone.IsDefault(new(gone.Configure)), gone.Order0
|
||||
}
|
||||
|
||||
type configure struct {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gone-io/gone"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
@ -11,10 +12,10 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NewHttInjector() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
func NewHttInjector() (gone.Goner, gone.GonerId) {
|
||||
return &httpInjector{
|
||||
bindFuncs: make([]BindFieldFunc, 0),
|
||||
}, gone.IdHttpInjector, gone.IsDefault(true)
|
||||
}, gone.IdHttpInjector
|
||||
}
|
||||
|
||||
type httpInjector struct {
|
||||
@ -88,14 +89,14 @@ const keyQuery = "query"
|
||||
const keyCookie = "cookie"
|
||||
|
||||
func unsupportedAttributeType(fieldName string) error {
|
||||
return gone.NewInnerErrorSkip(fmt.Sprintf("cannot inject %s,unsupported attribute type; ref doc: https://goner.fun/references/http-inject.html", fieldName), gone.InjectError, 2)
|
||||
return gone.NewInnerErrorSkip(fmt.Sprintf("inject attribute %s failed; unsupported attribute type; ref doc: https://goner.fun/references/http-inject.html", fieldName), gone.InjectError, 2)
|
||||
}
|
||||
func unsupportedKindConfigure(fieldName string) error {
|
||||
return gone.NewInnerErrorSkip(fmt.Sprintf("cannot inject %s,unsupported kind configure; ref doc: https://goner.fun/references/http-inject.html", fieldName), gone.InjectError, 2)
|
||||
func unsupportedKindConfigure(fieldName string, kind string) error {
|
||||
return gone.NewInnerErrorSkip(fmt.Sprintf("inject attribute %s failed; unsupported kind(%s) configure; ref doc: https://goner.fun/references/http-inject.html", fieldName, kind), gone.InjectError, 2)
|
||||
}
|
||||
|
||||
func cannotInjectBodyMoreThanOnce(fieldName string) error {
|
||||
return gone.NewInnerErrorSkip(fmt.Sprintf("cannot inject %s,http body inject only support inject once; ref doc: https://goner.fun/en/references/http-inject.md", fieldName), gone.InjectError, 2)
|
||||
return gone.NewInnerErrorSkip(fmt.Sprintf("inject attribute %s failed, http body injection kind only support inject once in each request; ref doc: https://goner.fun/en/references/http-inject.md", fieldName), gone.InjectError, 2)
|
||||
}
|
||||
|
||||
func injectParseStringParameterError(k reflect.Kind, kind, key string, err error) gone.Error {
|
||||
@ -229,6 +230,17 @@ func (s *httpInjector) injectBody(kind, key string, field reflect.StructField) (
|
||||
}
|
||||
return nil
|
||||
}, nil
|
||||
case reflect.String:
|
||||
return func(ctx *gin.Context, structVale reflect.Value) error {
|
||||
v := fieldByIndexFromStructValue(structVale, field.Index, field.IsExported(), field.Type)
|
||||
all, err := io.ReadAll(ctx.Request.Body)
|
||||
if err != nil {
|
||||
return NewParameterError(err.Error())
|
||||
}
|
||||
v.SetString(string(all))
|
||||
return nil
|
||||
}, nil
|
||||
|
||||
default:
|
||||
return nil, unsupportedAttributeType(field.Name)
|
||||
}
|
||||
@ -243,7 +255,7 @@ func (s *httpInjector) injectByKind(kind, key string, field reflect.StructField)
|
||||
case keyBody:
|
||||
return s.injectBody(kind, key, field)
|
||||
default:
|
||||
return nil, unsupportedKindConfigure(field.Name)
|
||||
return nil, unsupportedKindConfigure(field.Name, kind)
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,7 +403,7 @@ func (s *httpInjector) parseStringValueAndInject(kind, key string, field reflect
|
||||
return context.Query(key), nil
|
||||
}
|
||||
default:
|
||||
return nil, unsupportedKindConfigure(field.Name)
|
||||
return nil, unsupportedKindConfigure(field.Name, kind)
|
||||
}
|
||||
|
||||
bits := bitSize(t.Kind())
|
||||
@ -404,7 +416,7 @@ func (s *httpInjector) parseStringValueAndInject(kind, key string, field reflect
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Set(reflect.ValueOf(value))
|
||||
v.SetString(value)
|
||||
return nil
|
||||
}, nil
|
||||
|
||||
@ -415,7 +427,7 @@ func (s *httpInjector) parseStringValueAndInject(kind, key string, field reflect
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v.Set(reflect.ValueOf(stringToBool(value)))
|
||||
v.SetBool(stringToBool(value))
|
||||
return nil
|
||||
}, nil
|
||||
case reflect.Int, reflect.Int64, reflect.Int32, reflect.Int16, reflect.Int8:
|
||||
|
@ -135,10 +135,11 @@ func Test_httpInjector_inject(t *testing.T) {
|
||||
Uint16Slice []uint16
|
||||
FloatSlice []float32
|
||||
|
||||
Body Body
|
||||
BodyPtr *Body
|
||||
BodyMap map[string]any
|
||||
BodySlice []any
|
||||
Body Body
|
||||
BodyPtr *Body
|
||||
StringBody string
|
||||
BodyMap map[string]any
|
||||
BodySlice []any
|
||||
}{}
|
||||
|
||||
tests := []struct {
|
||||
@ -753,7 +754,7 @@ func Test_httpInjector_inject(t *testing.T) {
|
||||
|
||||
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, err.(gone.Error).Msg(), unsupportedKindConfigure("Str").(gone.Error).Msg())
|
||||
assert.Equal(t, err.(gone.Error).Msg(), unsupportedKindConfigure("Str", "x").(gone.Error).Msg())
|
||||
return false
|
||||
},
|
||||
|
||||
@ -912,6 +913,32 @@ func Test_httpInjector_inject(t *testing.T) {
|
||||
}, req.Body)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "inject by kind, inject body string",
|
||||
fieldName: "StringBody",
|
||||
kind: keyBody,
|
||||
key: stringKey,
|
||||
ctx: &context,
|
||||
|
||||
before: func() {
|
||||
body := Body{
|
||||
X: 100,
|
||||
Y: stringVal,
|
||||
}
|
||||
marshal, _ := json.Marshal(body)
|
||||
context.Request.Body = io.NopCloser(bytes.NewBuffer(marshal))
|
||||
},
|
||||
|
||||
wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
|
||||
assert.Nil(t, err)
|
||||
return true
|
||||
},
|
||||
|
||||
bindErr: func(t assert.TestingT, err error) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "{\"x\":100,\"y\":\"gone is best\"}", req.StringBody)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "inject by kind, inject body Struct, parse error",
|
||||
fieldName: "Body",
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
// `statRequestTime`,用于在日志中打印统计的请求耗时,可以通过设置配置项(`server.log.show-request-time=false`)来关闭
|
||||
// `accessLog`,用于在日志中打印请求、响应信息
|
||||
func NewGinProcessor() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &sysProcessor{}, gone.IdGoneGinProcessor, gone.IsDefault(true)
|
||||
return &sysProcessor{}, gone.IdGoneGinProcessor, gone.Order1
|
||||
}
|
||||
|
||||
type sysProcessor struct {
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
// NewGinProxy 新建代理器
|
||||
func NewGinProxy() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &proxy{}, gone.IdGoneGinProxy, gone.IsDefault(true)
|
||||
func NewGinProxy() (gone.Goner, gone.GonerId) {
|
||||
return &proxy{}, gone.IdGoneGinProxy
|
||||
}
|
||||
|
||||
type proxy struct {
|
||||
@ -141,7 +141,7 @@ func (p *proxy) buildProxyFn(x HandlerFunc, funcName string, last bool) gin.Hand
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
p.Panicf("build Proxy func for \033[31m%s\033[0m error:\n\n%s", funcName, err)
|
||||
}
|
||||
|
||||
fv := reflect.ValueOf(x)
|
||||
|
@ -144,13 +144,15 @@ func Test_proxy_Proxy(t *testing.T) {
|
||||
t.Run("Inject Error", func(t *testing.T) {
|
||||
defer func() {
|
||||
err := recover()
|
||||
assert.Error(t, err.(error))
|
||||
assert.NotNil(t, err)
|
||||
}()
|
||||
|
||||
injector.EXPECT().StartBindFuncs()
|
||||
|
||||
proxy.ProxyForMiddleware(func(in struct {
|
||||
x gone.Logger `gone:"xxx"`
|
||||
}) {
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
@ -12,10 +12,10 @@ import (
|
||||
|
||||
// NewGinResponser 新建系统默认的响应处理器
|
||||
// 注入的ID为:gone-gin-responser (`gone.IdGoneGinResponser`)
|
||||
func NewGinResponser() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
func NewGinResponser() (gone.Goner, gone.GonerId) {
|
||||
return &responser{
|
||||
wrappedDataFunc: wrapFunc,
|
||||
}, gone.IdGoneGinResponser, gone.IsDefault(true)
|
||||
}, gone.IdGoneGinResponser
|
||||
}
|
||||
|
||||
type res[T any] struct {
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestNewGinResponser(t *testing.T) {
|
||||
_, _, _ = NewGinResponser()
|
||||
_, _ = NewGinResponser()
|
||||
}
|
||||
|
||||
func (r *responser) Go(func()) {}
|
||||
@ -162,7 +162,7 @@ func Test_responser_Failed(t *testing.T) {
|
||||
|
||||
ctx.EXPECT().String(gomock.Any(), gomock.Any()).Do(func(code int, format string, values ...any) {
|
||||
assert.Equal(t, http.StatusBadRequest, code)
|
||||
assert.Equal(t, "GoneError(code=1):test", format)
|
||||
assert.Equal(t, "GoneError(code=1); test", format)
|
||||
})
|
||||
r.Failed(ctx, x)
|
||||
})
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
// NewGinRouter 用于创建系统根路由
|
||||
func NewGinRouter() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &router{id: incr}, gone.IdGoneGinRouter, gone.IsDefault(true)
|
||||
func NewGinRouter() (gone.Goner, gone.GonerId, gone.GonerOption, gone.GonerOption, gone.Order) {
|
||||
return &router{id: incr}, gone.IdGoneGinRouter, gone.IsDefault(new(gone.RouteGroup)), gone.IsDefault(new(gone.IRouter)), gone.Order0
|
||||
}
|
||||
|
||||
var incr = 0
|
||||
|
@ -10,11 +10,11 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
func NewGinServer() (gone.Goner, gone.GonerId, gone.GonerOption, gone.GonerOption) {
|
||||
func NewGinServer() (gone.Goner, gone.GonerOption, gone.GonerOption) {
|
||||
s := server{
|
||||
createListener: createListener,
|
||||
}
|
||||
return &s, gone.IdGoneGin, gone.IsDefault(true), gone.Order2
|
||||
return &s, gone.IdGoneGin, gone.Order2
|
||||
}
|
||||
|
||||
func createListener(s *server) (err error) {
|
||||
@ -57,7 +57,7 @@ func (s *server) Start(cemetery gone.Cemetery) error {
|
||||
Handler: s,
|
||||
}
|
||||
|
||||
s.Infof("Server Listen At %s", s.address)
|
||||
s.Infof("Server Listen At http://%s", s.address)
|
||||
s.Go(s.serve)
|
||||
return nil
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ func NewLogger() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
Logger: logrus.StandardLogger(),
|
||||
}
|
||||
log.ResetLog()
|
||||
return log, gone.IdGoneLogger, gone.IsDefault(true)
|
||||
return log, gone.IdGoneLogger, gone.IsDefault(new(gone.Logger))
|
||||
}
|
||||
|
||||
type logger struct {
|
||||
|
@ -57,7 +57,7 @@ func RedisPriest(cemetery gone.Cemetery) error {
|
||||
}
|
||||
|
||||
func SchedulePriest(cemetery gone.Cemetery) error {
|
||||
_ = BasePriest(cemetery)
|
||||
_ = RedisPriest(cemetery)
|
||||
_ = schedule.Priest(cemetery)
|
||||
return nil
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ import (
|
||||
)
|
||||
|
||||
func NewRedisCache() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &cache{}, gone.IdGoneRedisCache, gone.IsDefault(true)
|
||||
return &cache{}, gone.IdGoneRedisCache, gone.IsDefault(new(Cache))
|
||||
}
|
||||
|
||||
func NewRedisKey() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &cache{}, gone.IdGoneRedisKey, gone.IsDefault(true)
|
||||
return &cache{}, gone.IdGoneRedisKey, gone.IsDefault(new(Key))
|
||||
}
|
||||
|
||||
type cache struct {
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NewCacheProvider() (gone.Vampire, gone.GonerId, gone.GonerOption) {
|
||||
return &cacheProvider{}, gone.IdGoneRedisProvider, gone.IsDefault(true)
|
||||
func NewCacheProvider() (gone.Vampire, gone.GonerId) {
|
||||
return &cacheProvider{}, gone.IdGoneRedisProvider
|
||||
}
|
||||
|
||||
type cacheProvider struct {
|
||||
|
@ -17,7 +17,7 @@ end`
|
||||
var ErrorLockFailed = errors.New("not lock success")
|
||||
|
||||
func NewRedisLocker() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &locker{}, gone.IdGoneRedisLocker, gone.IsDefault(true)
|
||||
return &locker{}, gone.IdGoneRedisLocker, gone.IsDefault(new(Locker))
|
||||
}
|
||||
|
||||
type locker struct {
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func NewRedisPool() (gone.Angel, gone.GonerId, gone.GonerOption) {
|
||||
return &pool{}, gone.IdGoneRedisPool, gone.IsDefault(true)
|
||||
return &pool{}, gone.IdGoneRedisPool, gone.IsDefault(new(Pool))
|
||||
}
|
||||
|
||||
type pool struct {
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
|
||||
const IdGoneRedisInner = "gone-redis-inner"
|
||||
|
||||
func NewInner() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &inner{}, IdGoneRedisInner, gone.IsDefault(true)
|
||||
func NewInner() (gone.Goner, gone.GonerId) {
|
||||
return &inner{}, IdGoneRedisInner
|
||||
}
|
||||
|
||||
type inner struct {
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewSchedule() (gone.Goner, gone.GonerId, gone.GonerOption, gone.GonerOption) {
|
||||
return &schedule{}, gone.IdGoneSchedule, gone.IsDefault(true), gone.Order4
|
||||
func NewSchedule() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &schedule{}, gone.IdGoneSchedule, gone.Order4
|
||||
}
|
||||
|
||||
type schedule struct {
|
||||
@ -46,7 +46,7 @@ func (s *schedule) Start(gone.Cemetery) error {
|
||||
if err != nil {
|
||||
panic("cron.AddFunc for " + string(jobName) + " err:" + err.Error())
|
||||
}
|
||||
s.Infof("Add cron item: %s :%s", spec, jobName)
|
||||
s.Infof("Add cron item: %s => %s : %s", spec, jobName, gone.GetFuncName(fn))
|
||||
})
|
||||
}
|
||||
s.cronTab.Start()
|
||||
|
@ -2,24 +2,6 @@ package tracer
|
||||
|
||||
import "github.com/gone-io/gone"
|
||||
|
||||
// Tracer 日志追踪,用于给同一个调用链路赋予统一的traceId,方便日志追踪
|
||||
// Tracer is used to assign a unified traceId to the same call link to facilitate log tracking
|
||||
// Deprecated use gone.Tracer instead
|
||||
type Tracer = gone.Tracer
|
||||
|
||||
//type Tracer interface {
|
||||
//
|
||||
// //SetTraceId 设置TraceId;给调用函数设置一个`traceId`,如果traceId为空字符串,将生成自动一个
|
||||
// SetTraceId(traceId string, fn func())
|
||||
//
|
||||
// //GetTraceId 获取当前协程的traceId
|
||||
// GetTraceId() string
|
||||
//
|
||||
// //Go 开启一个新的协程,用于替代语法操作`go fn()`,在新的协程中将自动携带当前协程的`traceId`
|
||||
// Go(fn func())
|
||||
//
|
||||
// //Recover 捕获 panic
|
||||
// Recover()
|
||||
//
|
||||
// //RecoverSetTraceId SetTraceId 且 捕获 panic
|
||||
// RecoverSetTraceId(traceId string, fn func())
|
||||
//}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func NewTracer() (gone.Goner, gone.GonerId, gone.GonerOption, gone.GonerOption) {
|
||||
return &tracer{}, gone.IdGoneTracer, gone.IsDefault(true), gone.Order0
|
||||
return &tracer{}, gone.IdGoneTracer, gone.IsDefault(new(gone.Tracer)), gone.Order0
|
||||
}
|
||||
|
||||
type tracer struct {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
const TraceIdHeaderKey = "X-Trace-ID"
|
||||
|
||||
func NewReq() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &r{}, gone.IdGoneReq, gone.IsDefault(true)
|
||||
return &r{}, gone.IdGoneReq, gone.IsDefault(new(Client))
|
||||
}
|
||||
|
||||
type r struct {
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func NewConfigure() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &configure{}, gone.IdGoneConfigure, gone.IsDefault(true)
|
||||
return &configure{}, gone.IdGoneConfigure, gone.IsDefault(new(gone.Configure))
|
||||
}
|
||||
|
||||
type configure struct {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
func NewXormEngine() (gone.Angel, gone.GonerId, gone.GonerOption, gone.GonerOption) {
|
||||
return &engine{
|
||||
newFunc: newEngine,
|
||||
}, gone.IdGoneXorm, gone.IsDefault(true), gone.Order3
|
||||
}, gone.IdGoneXorm, gone.IsDefault(new(gone.XormEngine)), gone.Order3
|
||||
}
|
||||
|
||||
func newEngine(driverName string, dataSourceName string) (xorm.EngineInterface, error) {
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
)
|
||||
import "gopkg.in/natefinch/lumberjack.v2"
|
||||
|
||||
func NewZapLogger() (gone.Goner, gone.GonerId, gone.IsDefault) {
|
||||
return &log{}, "zap", true
|
||||
func NewZapLogger() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
return &log{}, "zap", gone.IsDefault(new(Logger))
|
||||
}
|
||||
|
||||
type log struct {
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func NewSugar() (gone.Goner, gone.GonerId, gone.IsDefault) {
|
||||
func NewSugar() (gone.Goner, gone.GonerId, gone.GonerOption) {
|
||||
config := zap.NewDevelopmentConfig()
|
||||
config.EncoderConfig.ConsoleSeparator = "|"
|
||||
config.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
|
||||
@ -15,7 +15,7 @@ func NewSugar() (gone.Goner, gone.GonerId, gone.IsDefault) {
|
||||
}
|
||||
return &sugar{
|
||||
SugaredLogger: logger.Sugar(),
|
||||
}, gone.IdGoneLogger, true
|
||||
}, gone.IdGoneLogger, gone.IsDefault(new(gone.Logger))
|
||||
}
|
||||
|
||||
type sugar struct {
|
||||
|
@ -23,8 +23,8 @@ func New(priests ...Priest) Heaven {
|
||||
h.
|
||||
cemetery.
|
||||
Bury(NewSimpleLogger()).
|
||||
Bury(&h, IdGoneHeaven, IsDefault(true)).
|
||||
Bury(cemetery, IdGoneCemetery, IsDefault(true))
|
||||
Bury(&h, IdGoneHeaven, IsDefault(new(Heaven))).
|
||||
Bury(cemetery, IdGoneCemetery, IsDefault(new(Cemetery)))
|
||||
return &h
|
||||
}
|
||||
|
||||
|
10
help.go
10
help.go
@ -101,6 +101,16 @@ func GetInterfaceType[T any](t *T) reflect.Type {
|
||||
return reflect.TypeOf(t).Elem()
|
||||
}
|
||||
|
||||
type defaultType struct {
|
||||
t reflect.Type
|
||||
}
|
||||
|
||||
func (d defaultType) option() {}
|
||||
|
||||
func IsDefault[T any](t *T) GonerOption {
|
||||
return defaultType{t: GetInterfaceType(t)}
|
||||
}
|
||||
|
||||
func WrapNormalFnToProcess(fn any) Process {
|
||||
return func(cemetery Cemetery) error {
|
||||
args, err := cemetery.InjectFuncParameters(fn, nil, nil)
|
||||
|
@ -70,8 +70,9 @@ func TestBlank(t *testing.T) {
|
||||
id := GonerId("")
|
||||
id.option()
|
||||
|
||||
isDefault := IsDefault(true)
|
||||
isDefault.option()
|
||||
d := defaultType{}
|
||||
d.option()
|
||||
|
||||
order := Order(1)
|
||||
order.option()
|
||||
}
|
||||
|
24
interface.go
24
interface.go
@ -9,32 +9,28 @@ import (
|
||||
|
||||
//go:generate sh -c "mockgen -package=gone -self_package=github.com/gone-io/gone -source=interface.go -destination=mock_test.go"
|
||||
|
||||
type Flag struct{}
|
||||
|
||||
func (g *Flag) goneFlag() {}
|
||||
|
||||
// Goner which is an abstraction of injectable objects: can inject other Goner, can be injected by other Goner.
|
||||
type Goner interface {
|
||||
goneFlag()
|
||||
}
|
||||
|
||||
type identity interface {
|
||||
GetId() GonerId
|
||||
}
|
||||
|
||||
type GonerOption interface {
|
||||
option()
|
||||
}
|
||||
|
||||
type Flag struct{}
|
||||
|
||||
func (g *Flag) goneFlag() {}
|
||||
|
||||
type identity interface {
|
||||
GetId() GonerId
|
||||
}
|
||||
|
||||
// GonerId Goner's id
|
||||
type GonerId string
|
||||
|
||||
func (GonerId) option() {}
|
||||
|
||||
type IsDefault bool
|
||||
|
||||
func (IsDefault) option() {}
|
||||
|
||||
type Order int
|
||||
|
||||
func (Order) option() {}
|
||||
@ -52,8 +48,8 @@ type Tomb interface {
|
||||
GetGoner() Goner
|
||||
GonerIsRevive(flags ...bool) bool
|
||||
|
||||
IsDefault() bool
|
||||
SetDefault(isDefault bool) Tomb
|
||||
SetDefault(reflect.Type) Tomb
|
||||
IsDefault(reflect.Type) bool
|
||||
|
||||
GetOrder() Order
|
||||
SetOrder(order Order) Tomb
|
||||
|
@ -6,8 +6,8 @@ import (
|
||||
|
||||
var _defaultLogger = &defaultLogger{Logger: new(log.Logger)}
|
||||
|
||||
func NewSimpleLogger() (Goner, GonerId, IsDefault) {
|
||||
return _defaultLogger, IdGoneLogger, true
|
||||
func NewSimpleLogger() (Goner, GonerId, GonerOption) {
|
||||
return _defaultLogger, IdGoneLogger, IsDefault(new(Logger))
|
||||
}
|
||||
|
||||
func GetSimpleLogger() Logger {
|
||||
|
23
tomb.go
23
tomb.go
@ -5,14 +5,18 @@ import (
|
||||
)
|
||||
|
||||
func NewTomb(goner Goner) Tomb {
|
||||
return &tomb{goner: goner}
|
||||
return &tomb{goner: goner, defaultTypes: make(map[reflect.Type]void)}
|
||||
}
|
||||
|
||||
type void struct{}
|
||||
|
||||
var voidValue void
|
||||
|
||||
type tomb struct {
|
||||
id GonerId
|
||||
goner Goner
|
||||
reviveFlag bool
|
||||
isDefault bool
|
||||
id GonerId
|
||||
goner Goner
|
||||
reviveFlag bool
|
||||
defaultTypes map[reflect.Type]void
|
||||
|
||||
order Order
|
||||
}
|
||||
@ -60,12 +64,13 @@ func (tombs Tombs) GetTomByType(t reflect.Type) (filterTombs []Tomb) {
|
||||
return
|
||||
}
|
||||
|
||||
func (t *tomb) IsDefault() bool {
|
||||
return t.isDefault
|
||||
func (t *tomb) IsDefault(T reflect.Type) bool {
|
||||
_, existed := t.defaultTypes[T]
|
||||
return existed
|
||||
}
|
||||
|
||||
func (t *tomb) SetDefault(isDefault bool) Tomb {
|
||||
t.isDefault = isDefault
|
||||
func (t *tomb) SetDefault(T reflect.Type) Tomb {
|
||||
t.defaultTypes[T] = voidValue
|
||||
return t
|
||||
}
|
||||
|
||||
|
2
tools/gone/priest/testdata/x/go.mod
vendored
2
tools/gone/priest/testdata/x/go.mod
vendored
@ -32,7 +32,7 @@ require (
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
1
tools/gone/priest/testdata/x/go.sum
vendored
1
tools/gone/priest/testdata/x/go.sum
vendored
@ -509,6 +509,7 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
Loading…
Reference in New Issue
Block a user