mirror of
https://github.com/gone-io/gone.git
synced 2025-01-23 01:00:23 +08:00
feat: Add Default Preparer for new code directory structure
This commit is contained in:
parent
612e26b120
commit
5fc2b15b2a
7
example/use_default/README.md
Normal file
7
example/use_default/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
# New code directory structure
|
||||
|
||||
## 1. `import.gone.go` and `init.gone.go` will be generated by `gonectr` automatically
|
||||
|
||||
## 2. `init.gone.go` is responsible for loading goner module to the `gone` framework
|
||||
|
||||
## 3. `import.gone.go` is responsible for importing all packages which contain goner module in the project
|
43
example/use_default/go.mod
Normal file
43
example/use_default/go.mod
Normal file
@ -0,0 +1,43 @@
|
||||
module use_default
|
||||
|
||||
go 1.22.2
|
||||
|
||||
require github.com/gone-io/gone v1.0.9
|
||||
|
||||
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.9 => ../../
|
||||
)
|
8
example/use_default/import.gone.go
Normal file
8
example/use_default/import.gone.go
Normal file
@ -0,0 +1,8 @@
|
||||
// Code generated by Goner. DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "use_default/internal/food"
|
||||
_ "use_default/internal/user"
|
||||
)
|
11
example/use_default/internal/food/food.go
Normal file
11
example/use_default/internal/food/food.go
Normal file
@ -0,0 +1,11 @@
|
||||
package food
|
||||
|
||||
import "github.com/gone-io/gone"
|
||||
|
||||
type iFood struct {
|
||||
gone.Flag
|
||||
}
|
||||
|
||||
func (s *iFood) Create() error {
|
||||
return nil
|
||||
}
|
9
example/use_default/internal/food/init.gone.go
Normal file
9
example/use_default/internal/food/init.gone.go
Normal file
@ -0,0 +1,9 @@
|
||||
// Code generated by Goner. DO NOT EDIT.
|
||||
|
||||
package food
|
||||
|
||||
import "github.com/gone-io/gone"
|
||||
|
||||
func init() {
|
||||
gone.Default.Load(&iFood{})
|
||||
}
|
12
example/use_default/internal/user/init.gone.go
Normal file
12
example/use_default/internal/user/init.gone.go
Normal file
@ -0,0 +1,12 @@
|
||||
// Code generated by Goner. DO NOT EDIT.
|
||||
|
||||
package user
|
||||
|
||||
import "github.com/gone-io/gone"
|
||||
|
||||
func init() {
|
||||
gone.
|
||||
Default.
|
||||
Load(&iUser{}).
|
||||
Load(&iSession{})
|
||||
}
|
15
example/use_default/internal/user/session.go
Normal file
15
example/use_default/internal/user/session.go
Normal file
@ -0,0 +1,15 @@
|
||||
package user
|
||||
|
||||
import "github.com/gone-io/gone"
|
||||
|
||||
type iSession struct {
|
||||
gone.Flag
|
||||
}
|
||||
|
||||
func (s *iSession) Put(any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *iSession) Get() (any, error) {
|
||||
return nil, nil
|
||||
}
|
11
example/use_default/internal/user/user.go
Normal file
11
example/use_default/internal/user/user.go
Normal file
@ -0,0 +1,11 @@
|
||||
package user
|
||||
|
||||
import "github.com/gone-io/gone"
|
||||
|
||||
type iUser struct {
|
||||
gone.Flag
|
||||
}
|
||||
|
||||
func (s *iUser) Hello() string {
|
||||
return "hello"
|
||||
}
|
19
example/use_default/main.go
Normal file
19
example/use_default/main.go
Normal file
@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gone-io/gone"
|
||||
"use_default/service"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gone.Default.Run(func(i struct {
|
||||
iFood service.IFood `gone:"*"`
|
||||
iSession service.ISession `gone:"*"`
|
||||
iUser service.IUser `gone:"*"`
|
||||
}) {
|
||||
_ = i.iSession.Put("ok")
|
||||
_ = i.iFood.Create()
|
||||
hello := i.iUser.Hello()
|
||||
println(hello)
|
||||
})
|
||||
}
|
5
example/use_default/service/i_food.go
Normal file
5
example/use_default/service/i_food.go
Normal file
@ -0,0 +1,5 @@
|
||||
package service
|
||||
|
||||
type IFood interface {
|
||||
Create() error
|
||||
}
|
6
example/use_default/service/i_session.go
Normal file
6
example/use_default/service/i_session.go
Normal file
@ -0,0 +1,6 @@
|
||||
package service
|
||||
|
||||
type ISession interface {
|
||||
Put(any) error
|
||||
Get() (any, error)
|
||||
}
|
5
example/use_default/service/i_user.go
Normal file
5
example/use_default/service/i_user.go
Normal file
@ -0,0 +1,5 @@
|
||||
package service
|
||||
|
||||
type IUser interface {
|
||||
Hello() string
|
||||
}
|
@ -47,6 +47,10 @@ type heaven struct {
|
||||
afterStopSignalWaitSecond int
|
||||
}
|
||||
|
||||
func (h *heaven) GetCemetery() Cemetery {
|
||||
return h.cemetery
|
||||
}
|
||||
|
||||
func (h *heaven) SetAfterStopSignalWaitSecond(sec int) {
|
||||
h.afterStopSignalWaitSecond = sec
|
||||
}
|
||||
|
@ -127,6 +127,8 @@ type Heaven interface {
|
||||
AfterStop(Process) Heaven
|
||||
|
||||
SetAfterStopSignalWaitSecond(sec int)
|
||||
|
||||
GetCemetery() Cemetery
|
||||
}
|
||||
|
||||
type AfterReviveError error
|
||||
|
10
prepare.go
10
prepare.go
@ -50,6 +50,14 @@ func (p *Preparer) Serve(fns ...any) {
|
||||
Stop()
|
||||
}
|
||||
|
||||
func (p *Preparer) Load(goner Goner) *Preparer {
|
||||
p.heaven.GetCemetery().Bury(goner)
|
||||
return p
|
||||
}
|
||||
func (p *Preparer) Bury(goner Goner) *Preparer {
|
||||
return p.Load(goner)
|
||||
}
|
||||
|
||||
func Prepare(priests ...Priest) *Preparer {
|
||||
h := New(priests...)
|
||||
|
||||
@ -58,6 +66,8 @@ func Prepare(priests ...Priest) *Preparer {
|
||||
}
|
||||
}
|
||||
|
||||
var Default = Prepare()
|
||||
|
||||
/*
|
||||
Run A Gone Program;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user