-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathmain.go
82 lines (76 loc) · 1.74 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
package main
import (
"context"
"embed"
"flag"
"fmt"
"os"
"runtime"
"github.com/tj/go-update"
"github.com/tj/go-update/progress"
"github.com/tj/go-update/stores/github"
"github.com/nfx/slrp/app"
"github.com/nfx/slrp/checker"
"github.com/nfx/slrp/history"
"github.com/nfx/slrp/ipinfo"
"github.com/nfx/slrp/pool"
"github.com/nfx/slrp/probe"
"github.com/nfx/slrp/refresher"
"github.com/nfx/slrp/serve"
"github.com/nfx/slrp/stats"
)
var version = "devel"
//go:embed ui/build
var embedFrontend embed.FS
func main() {
updatePtr := flag.Bool("update", false, "check for updates")
flag.Parse()
if *updatePtr {
m := &update.Manager{
Command: "slrp",
Store: &github.Store{
Owner: "nfx",
Repo: "slrp",
Version: version,
},
}
releases, err := m.LatestReleases()
if err != nil {
panic(err)
}
if len(releases) == 0 {
println("no updates")
return
}
asset := releases[0].FindTarball(runtime.GOOS, runtime.GOARCH)
if asset == nil {
fmt.Printf("no binary for %s %s\n", runtime.GOOS, runtime.GOARCH)
return
}
println() // whitespace
tarball, err := asset.DownloadProxy(progress.Reader)
if err != nil {
panic(err)
}
err = m.Install(tarball)
if err != nil {
panic(err)
}
os.Exit(0)
}
fmt.Printf("slrp v%s\n", version)
app.Run(context.Background(), app.Factories{
"ca": serve.NewCA,
"blacklist": probe.NewBlacklistApi,
"checker": checker.NewChecker,
"dashboard": serve.NewDashboard,
"history": history.NewHistory,
"ipinfo": ipinfo.NewLookup,
"mitm": serve.NewMitmProxyServer,
"pool": pool.NewPool,
"probe": probe.NewProbe,
"refresher": refresher.NewRefresher,
"stats": stats.NewStats,
"ui": app.MountSpaUI(embedFrontend),
})
}