-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
109 lines (96 loc) · 2.63 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"encoding/base64"
"flag"
"fmt"
"log"
"os"
"github.com/nicennnnnnnlee/freedomGo/grpc"
"github.com/nicennnnnnnlee/freedomGo/local"
lconf "github.com/nicennnnnnnlee/freedomGo/local/config"
"github.com/nicennnnnnnlee/freedomGo/remote"
rconf "github.com/nicennnnnnnlee/freedomGo/remote/config"
"gopkg.in/yaml.v2"
)
var (
version = "Unknown"
buildTime = "Unknown"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
fmt.Println("FreedomGo")
fmt.Println("\tVersion:\t", version)
fmt.Println("\tBuildTime:\t", buildTime)
var typeOfApp string
var configPath string
flag.StringVar(&typeOfApp, "type", "local", "模式local/remote/capture")
flag.StringVar(&typeOfApp, "t", "local", "模式local/remote/capture")
flag.StringVar(&configPath, "config", "./conf.local.yaml", "配置文件路径")
flag.StringVar(&configPath, "c", "./conf.local.yaml", "配置文件路径")
flag.Parse()
// 尝试读取环境变量的配置
val, exist := os.LookupEnv("APP_CONFIG_F0")
var configByte []byte
if exist {
configByte, _ = base64.StdEncoding.DecodeString(val)
}
switch typeOfApp {
case "local":
startLocalService(configPath, configByte)
case "remote":
startRemoteService(configPath, configByte)
case "capture":
local.Capture(configPath)
default:
flag.Usage()
fmt.Println("仅支持local或remote模式")
}
}
func startLocalService(path string, configByte []byte) {
var conf lconf.Local
// out, _ := yaml.Marshal(config.New())
// fmt.Println(string(out))
if configByte != nil {
err := yaml.Unmarshal(configByte, &conf)
if err != nil {
log.Fatalln(err)
}
} else {
yamlData, err := os.ReadFile(path)
if err != nil {
log.Fatalln(err)
}
err = yaml.Unmarshal(yamlData, &conf)
if err != nil {
log.Fatalln(err)
}
}
fmt.Printf("%+v\n", &conf)
grpc.Freedom_ServiceDesc.ServiceName = conf.GrpcServiceName
grpc.Freedom_Method = "/" + conf.GrpcServiceName + "/Pipe"
local.Start(&conf)
}
func startRemoteService(path string, configByte []byte) {
var conf rconf.Remote
// out, _ := yaml.Marshal(config.NewRemote())
// fmt.Println(string(out))
if configByte != nil {
err := yaml.Unmarshal(configByte, &conf)
if err != nil {
log.Fatalln(err)
}
} else {
yamlData, err := os.ReadFile(path)
if err != nil {
log.Fatalln(err)
}
err = yaml.Unmarshal(yamlData, &conf)
if err != nil {
log.Fatalln(err)
}
}
fmt.Println(&conf)
grpc.Freedom_ServiceDesc.ServiceName = conf.GrpcServiceName
grpc.Freedom_Method = "/" + conf.GrpcServiceName + "/Pipe"
remote.Start(&conf)
}