proxyport/main.go

63 lines
1.1 KiB
Go

package main
import (
"context"
"flag"
"git.makemake.in/kzkzzzz/mycommon/mylog"
"log"
"os"
"os/signal"
"proxyport/app/db"
"proxyport/app/forward"
"proxyport/app/web"
"sync"
"syscall"
)
var (
logLevel string
)
func main() {
log.SetOutput(os.Stdout)
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.StringVar(&web.Config.WebName, "web_name", "", "web name")
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()
}()
go func() {
defer wg.Done()
forward.ListenerManager.Start(ctx)
}()
go func() {
defer wg.Done()
web.Start(ctx)
}()
wg.Wait()
}