Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a850005f0b | ||
|
|
3a435be177 | ||
|
|
7b9c3cf531 | ||
|
|
c4ec53b4d0 | ||
|
|
f75985f797 | ||
|
|
6df4738d4b |
@@ -9,7 +9,7 @@
|
|||||||
- ORM [gorm](https://github.com/go-gorm/gorm)
|
- ORM [gorm](https://github.com/go-gorm/gorm)
|
||||||
- 文档 [swagger](https://github.com/swaggo/swag)
|
- 文档 [swagger](https://github.com/swaggo/swag)
|
||||||
- 数据生成 [gofakeit](github.com/brianvoe/gofakeit)
|
- 数据生成 [gofakeit](github.com/brianvoe/gofakeit)
|
||||||
- 框架增强 [gen](github.com/rogeecn/gen)
|
- http框架增强 [fen](github.com/rogeecn/fen)
|
||||||
- 依赖注入 [dig](go.uber.org/dig)
|
- 依赖注入 [dig](go.uber.org/dig)
|
||||||
|
|
||||||
### 命令行工具 atomctl
|
### 命令行工具 atomctl
|
||||||
@@ -271,4 +271,4 @@ module/
|
|||||||
go run .
|
go run .
|
||||||
```
|
```
|
||||||
13. 访问
|
13. 访问
|
||||||
[localhost:9800/doc/index.html](localhost:9800/doc/index.html)
|
[localhost:9800/doc/index.html](http://localhost:9800/doc/index.html)
|
||||||
@@ -34,6 +34,14 @@ func Serve(providers container.Providers, opts ...Option) error {
|
|||||||
opt(rootCmd)
|
opt(rootCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rootCmd.SilenceErrors = true
|
||||||
|
rootCmd.SilenceUsage = true
|
||||||
|
rootCmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
|
||||||
|
cmd.Println(err)
|
||||||
|
cmd.Println(cmd.UsageString())
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
|
||||||
defaultCfgFile := fmt.Sprintf(".%s.toml", rootCmd.Use)
|
defaultCfgFile := fmt.Sprintf(".%s.toml", rootCmd.Use)
|
||||||
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file path, lookup in dir: $HOME, $PWD, /etc, /usr/local/etc, filename: "+defaultCfgFile)
|
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file path, lookup in dir: $HOME, $PWD, /etc, /usr/local/etc, filename: "+defaultCfgFile)
|
||||||
|
|
||||||
|
|||||||
@@ -18,15 +18,19 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
closeable = make([]func(), 0)
|
||||||
if err := Container.Provide(func() context.Context {
|
if err := Container.Provide(func() context.Context {
|
||||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
Close()
|
||||||
|
cancel()
|
||||||
|
}()
|
||||||
Cancel = cancel
|
Cancel = cancel
|
||||||
return ctx
|
return ctx
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
closeable = make([]func(), 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddCloseAble(c func()) {
|
func AddCloseAble(c func()) {
|
||||||
|
|||||||
8
contracts/http.go
Normal file
8
contracts/http.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package contracts
|
||||||
|
|
||||||
|
type HttpRoute interface{}
|
||||||
|
|
||||||
|
type HttpService interface {
|
||||||
|
Serve() error
|
||||||
|
GetEngine() interface{}
|
||||||
|
}
|
||||||
6
contracts/micro.go
Normal file
6
contracts/micro.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package contracts
|
||||||
|
|
||||||
|
type MicroService interface {
|
||||||
|
Serve() error
|
||||||
|
GetEngine() any
|
||||||
|
}
|
||||||
@@ -7,5 +7,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TruncateTable(db *gorm.DB, table string) {
|
func TruncateTable(db *gorm.DB, table string) {
|
||||||
|
if db.Dialector.Name() == "postgres" {
|
||||||
|
db.Exec(fmt.Sprintf("TRUNCATE TABLE %s RESTART IDENTITY", table))
|
||||||
|
return
|
||||||
|
}
|
||||||
db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table))
|
db.Exec(fmt.Sprintf("TRUNCATE TABLE %s", table))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user