proxyport/main.go

60 lines
998 B
Go
Raw Permalink Normal View History

2023-01-18 14:13:22 +08:00
package main
import (
2024-09-30 16:37:53 +08:00
"context"
"flag"
2023-04-21 18:20:54 +08:00
"git.makemake.in/kzkzzzz/mycommon/mylog"
2024-09-30 16:37:53 +08:00
"os"
"os/signal"
"proxyport/app/db"
"proxyport/app/forward"
"proxyport/app/web"
"sync"
"syscall"
)
var (
logLevel string
2023-01-18 14:13:22 +08:00
)
func main() {
2024-09-30 16:37:53 +08:00
flag.StringVar(&logLevel, "log_level", "debug", "log level")
flag.StringVar(&web.Config.ListenAddr, "listen_addr", ":28083", "web port")
flag.StringVar(&web.Config.User, "user", "", "web user")
flag.StringVar(&web.Config.Password, "password", "", "web password")
flag.Parse()
mylog.SetLogLevel(logLevel)
mylog.Init()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
db.InitDB()
wg := &sync.WaitGroup{}
wg.Add(3)
go func() {
defer wg.Done()
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
mylog.Warnf("catch signal: %v", <-ch)
cancel()
}()
2023-01-19 11:34:30 +08:00
2024-09-30 16:37:53 +08:00
go func() {
defer wg.Done()
forward.ListenerManager.Start(ctx)
}()
2024-02-19 19:11:43 +08:00
2024-09-30 16:37:53 +08:00
go func() {
defer wg.Done()
web.Start(ctx)
}()
2024-06-24 14:24:35 +08:00
2024-09-30 16:37:53 +08:00
wg.Wait()
2023-01-18 14:13:22 +08:00
}