-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
64 lines (57 loc) · 1.13 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
package main
import (
"bytes"
"encoding/json"
"log"
"os"
"github.com/shoriwe/fullproxy/v4/compose"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v3"
)
const JsonFlag = "json"
var app = &cli.App{
Commands: []*cli.Command{
{
Name: "compose",
Usage: "start fullproxy services based on the defined compose contract",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: JsonFlag,
Usage: "decode compose as JSON",
},
},
Action: func(ctx *cli.Context) error {
composeFile := "fullproxy-compose.yaml"
if ctx.Args().Len() == 1 {
composeFile = ctx.Args().First()
}
composeContents, err := os.ReadFile(composeFile)
if err != nil {
return err
}
var c compose.Compose
if ctx.Bool(JsonFlag) {
err = json.NewDecoder(bytes.NewReader(composeContents)).Decode(&c)
if err != nil {
return err
}
} else {
err = yaml.NewDecoder(bytes.NewReader(composeContents)).Decode(&c)
if err != nil {
return err
}
}
err = c.Start()
return err
},
},
},
}
func init() {
}
func main() {
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}