-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
81 lines (70 loc) · 1.8 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
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli/v2"
"github.com/alileza/bridge/httpredirector"
"github.com/alileza/bridge/portal"
"github.com/alileza/bridge/storage"
)
func main() {
var err error
app := &cli.App{
Flags: []cli.Flag{
&cli.StringFlag{
Name: "listen-address",
Aliases: []string{"l", "listen"},
Value: "0.0.0.0:80",
Usage: "HTTP listen address, e.g. 0.0.0.0:80",
EnvVars: []string{"LISTEN_ADDRESS"},
},
&cli.StringFlag{
Name: "storage-dir",
Aliases: []string{"s", "storage"},
Value: "./bridgedata",
Usage: "storage dir (default: ./bridgedata)",
},
&cli.BoolFlag{
Name: "proxy-enabled",
Aliases: []string{"p", "proxy"},
Value: false,
Usage: "enable proxy mode, it's useful for development UI",
EnvVars: []string{"PROXY_ENABLED"},
Hidden: true,
},
&cli.StringFlag{
Name: "proxy-url",
Aliases: []string{"u", "url"},
Value: "http://localhost:5173",
Usage: "proxy URL for UI, e.g. http://localhost:5173",
EnvVars: []string{"PROXY_URL"},
Hidden: true,
},
},
Action: func(c *cli.Context) error {
listenAddress := c.String("listen-address")
proxyEnabled := c.Bool("proxy-enabled")
proxyURL := c.String("proxy-url")
storageDir := c.String("storage-dir")
os.MkdirAll(storageDir, 0755)
store, err := storage.NewJSONFileStorage(storageDir)
if err != nil {
return fmt.Errorf("error initializing storage: %s", err)
}
prtl := portal.NewServer(&portal.Options{
ListenAddress: listenAddress,
UIProxyEnabled: proxyEnabled,
UIProxyURL: proxyURL,
Redirector: &httpredirector.HTTPRedirector{
Storage: store,
},
})
return prtl.Start()
},
}
err = app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}