-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (37 loc) · 893 Bytes
/
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
package main
import (
"log"
"log/slog"
"os"
"os/signal"
"syscall"
"github.com/alexng353/ihostproxy/context"
"github.com/alexng353/ihostproxy/credentials"
"github.com/alexng353/ihostproxy/webui"
"github.com/caarlos0/env/v10"
)
var creds = credentials.Get()
var ctx = context.Env{}
func main() {
if err := env.Parse(&ctx); err != nil {
log.Fatal(err)
}
if ctx.WebUIPass != "" && ctx.WebUIUser != "" {
err := creds.AddAdmin(ctx.WebUIUser, ctx.WebUIPass)
if err != nil {
slog.Error("Failed to add admin", "error", err)
}
}
disableProxy := os.Getenv("DISABLE_PROXY") == "1"
if !disableProxy {
go startProxy(ctx)
}
disableWebui := os.Getenv("DISABLE_WEBUI") == "1"
if !disableWebui {
go webui.StartWebUI(ctx)
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
slog.String("signal", sig.String())
}