mirror of
https://github.com/wonli/aqi.git
synced 2025-12-24 10:40:58 +08:00
aqi-cli
This commit is contained in:
35
internal/cli/templates/default/cmd/api.go.tmpl
Normal file
35
internal/cli/templates/default/cmd/api.go.tmpl
Normal file
@@ -0,0 +1,35 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/wonli/aqi"
|
||||
|
||||
"{{.PackageName}}/internal/dbc"
|
||||
"{{.PackageName}}/internal/router"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(api)
|
||||
}
|
||||
|
||||
var api = &cobra.Command{
|
||||
Use: "api",
|
||||
Short: "启动API",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
app := aqi.Init(
|
||||
aqi.ConfigFile(configFile),
|
||||
aqi.HttpServer("Api", "apiPort"),
|
||||
)
|
||||
|
||||
dbc.InitDBC()
|
||||
|
||||
g := gin.Default()
|
||||
|
||||
go router.Api(g)
|
||||
go router.Actions(app)
|
||||
|
||||
app.WithHttpServer(g)
|
||||
app.Start()
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user