-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
67 lines (55 loc) · 1.12 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
67
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*/
package main
import (
"context"
"fmt"
"github.com/eclipse-xpanse/policy-man/config"
"github.com/eclipse-xpanse/policy-man/log"
"github.com/eclipse-xpanse/policy-man/server"
"github.com/spf13/pflag"
)
// Add comments to describe server openAPI information
//
// @title OpenAPI of policy-man
// @version 1.0
// @description OpenAPI of policy-man server
func main() {
cfg, err := config.LoadConf()
if err != nil {
fmt.Print("loading config failed\n")
return
}
if isFlagPassed("version") {
fmt.Println(version)
return
}
if isFlagPassed("help") {
return
}
fmt.Print(config.Logo)
if err = log.InitLog(cfg.Log.Level, cfg.Log.Path); err != nil {
return
}
ctx := context.Background()
go func() {
err := server.RunHTTPServer(ctx, cfg)
if err != nil {
log.Errorf("run http server failed: %v", err)
return
}
}()
<-ctx.Done()
}
func isFlagPassed(name string) bool {
found := false
config.RootCmd.Flags().Visit(func(flag *pflag.Flag) {
if flag.Name == name {
found = true
return
}
})
return found
}