/
main.go
40 lines (31 loc) · 835 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
package main
import (
"context"
"log/slog"
"os"
)
func main() {
ctx := context.Background()
infoLog := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{}))
errorLog := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
AddSource: true,
}))
if len(os.Args) < 2 {
errorLog.Error("please provide a path to the configuration file")
os.Exit(1)
}
configPath := os.Args[1]
infoLog.Info("welcome to tiny proxy...")
infoLog.Info("loading configuration file", slog.String("path", configPath))
// TODO: accept the path from command line flags
config, err := LoadConfig(configPath)
if err != nil {
errorLog.Error("failed to load config, please check your configuration file")
panic(err)
}
proxy := New(config, infoLog, errorLog)
err = proxy.Start(ctx)
if err != nil {
panic(err)
}
}