-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathapi.go
63 lines (47 loc) · 1.17 KB
/
api.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
package cmd
import (
"finala/api"
"finala/api/config"
"finala/api/storage/elasticsearch"
"finala/serverutil"
"finala/visibility"
"os"
"os/signal"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var (
// port of the api
port int
)
// awsCMS will present the aws analyze command
var apiServer = &cobra.Command{
Use: "api",
Short: "Launch RESTful API",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
// Loading configuration file
configStruct, err := config.LoadAPI(cfgFile)
if err != nil {
log.Error(err)
os.Exit(1)
}
// Set application log level
visibility.SetLoggingLevel(configStruct.LogLevel)
storage, err := elasticsearch.NewStorageManager(configStruct.Storage.ElasticSearch)
if err != nil {
os.Exit(1)
}
apiManager := api.NewServer(port, storage, versionManager)
apiStopper := serverutil.RunAll(apiManager).StopFunc
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
<-stop // block until we are requested to stop
apiStopper()
},
}
// init will add aws command
func init() {
apiServer.PersistentFlags().IntVar(&port, "port", 8081, "lisinning port")
rootCmd.AddCommand(apiServer)
}