6 Commits

Author SHA1 Message Date
rogeecn
a850005f0b modify httpRoute interface 2023-07-31 18:46:20 +08:00
yanghao05
3a435be177 add contracts 2023-07-31 18:11:33 +08:00
yanghao05
7b9c3cf531 fix quit issues 2023-07-10 20:09:05 +08:00
yanghao05
c4ec53b4d0 fix issues 2023-07-06 19:05:29 +08:00
yanghao05
f75985f797 add silent call 2023-07-06 11:29:26 +08:00
yanghao05
6df4738d4b modify doc 2023-06-20 11:41:25 +08:00
6 changed files with 34 additions and 4 deletions

View File

@@ -9,7 +9,7 @@
- ORM [gorm](https://github.com/go-gorm/gorm)
- 文档 [swagger](https://github.com/swaggo/swag)
- 数据生成 [gofakeit](github.com/brianvoe/gofakeit)
- 框架增强 [gen](github.com/rogeecn/gen)
- http框架增强 [fen](github.com/rogeecn/fen)
- 依赖注入 [dig](go.uber.org/dig)
### 命令行工具 atomctl
@@ -271,4 +271,4 @@ module/
go run .
```
13. 访问
[localhost:9800/doc/index.html](localhost:9800/doc/index.html)
[localhost:9800/doc/index.html](http://localhost:9800/doc/index.html)

View File

@@ -34,6 +34,14 @@ func Serve(providers container.Providers, opts ...Option) error {
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)
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file path, lookup in dir: $HOME, $PWD, /etc, /usr/local/etc, filename: "+defaultCfgFile)

View File

@@ -18,15 +18,19 @@ var (
)
func init() {
closeable = make([]func(), 0)
if err := Container.Provide(func() context.Context {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
<-ctx.Done()
Close()
cancel()
}()
Cancel = cancel
return ctx
}); err != nil {
log.Fatal(err)
}
closeable = make([]func(), 0)
}
func AddCloseAble(c func()) {

8
contracts/http.go Normal file
View File

@@ -0,0 +1,8 @@
package contracts
type HttpRoute interface{}
type HttpService interface {
Serve() error
GetEngine() interface{}
}

6
contracts/micro.go Normal file
View File

@@ -0,0 +1,6 @@
package contracts
type MicroService interface {
Serve() error
GetEngine() any
}

View File

@@ -7,5 +7,9 @@ import (
)
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))
}