-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (54 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"github.com/spf13/cobra"
"gohub/app/cmd"
"gohub/app/cmd/make"
"gohub/bootstrap"
btsConfig "gohub/config"
"gohub/pkg/config"
"gohub/pkg/console"
"os"
)
func init() {
// Load the configuration information in the config directory
btsConfig.Initialize()
}
func main() {
// Application entry, the command cmd.CmdServer is called by default
var rootCmd = &cobra.Command{
Use: "Gohub",
Short: "A simple forum project",
Long: `Default will run "serve" command, you can use "-h" flag to see all subcommands`,
// All subcommands of rootCmd execute the following code
PersistentPreRun: func(command *cobra.Command, args []string) {
config.InitConfig(cmd.Env)
// Initialize Logger
bootstrap.SetupLogger()
// Initialize DB
bootstrap.SetupDB()
// Initialize Redis
bootstrap.SetupRedis()
// Initialize the cache
bootstrap.SetupCache()
},
}
// register subcommand
rootCmd.AddCommand(
cmd.Serve,
cmd.Key,
cmd.Play,
make.Make,
cmd.Migrate,
cmd.DBSeed,
cmd.Cache,
)
// Configure the web service to run by default
cmd.RegisterDefaultCmd(rootCmd, cmd.Serve)
// Register global parameters, --env
cmd.RegisterGlobalFlags(rootCmd)
// Execute the main command
if err := rootCmd.Execute(); err != nil {
console.Exit(fmt.Sprintf("Failed to run app with %v: %x", os.Args, err.Error()))
}
}