1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-19 10:57:05 +00:00

add a new example

This commit is contained in:
kataras
2022-06-04 02:42:33 +03:00
parent c201b6ccc8
commit c6911851f1
10 changed files with 483 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package cmd
import (
"github.com/kataras/my-iris-app/api"
"github.com/spf13/cobra"
)
const defaultConfigFilename = "server.dev.yml"
var (
serverConfig api.Configuration
)
// New returns a new root command.
// Usage:
// $ my-iris-app --config=server.yml
func New() *cobra.Command {
configFile := defaultConfigFilename
rootCmd := &cobra.Command{
Use: "my-iris-app",
Short: "My Command Line App",
Long: "The root command will start the HTTP server.",
Version: "v0.0.1",
SilenceErrors: true,
SilenceUsage: true,
TraverseChildren: true,
SuggestionsMinimumDistance: 1,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return serverConfig.BindFile(configFile)
},
RunE: func(cmd *cobra.Command, args []string) error {
return startServer()
},
}
// Shared flags.
flags := rootCmd.PersistentFlags()
flags.StringVar(&configFile, "config", configFile, "--config=server.yml a filepath which contains the YAML config format")
// Subcommands here.
return rootCmd
}
func startServer() error {
srv := api.NewServer(serverConfig)
return srv.Listen()
}