From e4c9049924c8f136b76617f1a0c4589deee9d5c6 Mon Sep 17 00:00:00 2001 From: lzf Date: Mon, 24 Jun 2024 14:24:35 +0800 Subject: [PATCH] update --- .gitignore | 5 ++++- app/config.go | 6 ++++-- app/proxy.go | 7 +++---- go.mod | 11 ++++++----- main.go | 13 +++++++------ 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 85eae03..f80d67e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .idea bin -go.sum \ No newline at end of file +go.sum +config.toml +temp +logs \ No newline at end of file diff --git a/app/config.go b/app/config.go index 5892061..e07e463 100644 --- a/app/config.go +++ b/app/config.go @@ -1,7 +1,9 @@ package app type ( - Conf map[string]ProxyItem + config struct { + Proxy map[string]ProxyItem + } ProxyItem struct { RemoteAddr []string @@ -9,4 +11,4 @@ type ( } ) -var ProxyMap = make(Conf) +var Conf = &config{} diff --git a/app/proxy.go b/app/proxy.go index 3c288b4..f6c471c 100644 --- a/app/proxy.go +++ b/app/proxy.go @@ -2,6 +2,7 @@ package app import ( "context" + "fmt" "git.makemake.in/kzkzzzz/mycommon/mylog" "io" "math/rand" @@ -19,9 +20,7 @@ var ( ) func Run() { - rand.Seed(time.Now().UnixNano()) - - for name, item := range ProxyMap { + for name, item := range Conf.Proxy { go listenTcp(name, item) } @@ -38,7 +37,7 @@ func Run() { } func listenTcp(name string, item ProxyItem) { - + fmt.Printf("%+v\n", item.LocalAddr) listen, err := net.Listen("tcp", item.LocalAddr) if err != nil { mylog.Errorf("[%s] listen err: %s", name, err) diff --git a/go.mod b/go.mod index 5ece30d..6257ca2 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,10 @@ module proxyport go 1.18 -require git.makemake.in/kzkzzzz/mycommon v0.0.0-20230421101858-aa0fb37da29c +require ( + git.makemake.in/kzkzzzz/mycommon v0.0.0-20240623062425-ebf5c21cde3a + github.com/spf13/pflag v1.0.5 +) require ( github.com/fsnotify/fsnotify v1.6.0 // indirect @@ -14,12 +17,10 @@ require ( github.com/spf13/afero v1.9.3 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/viper v1.14.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect - go.uber.org/atomic v1.10.0 // indirect - go.uber.org/multierr v1.9.0 // indirect - go.uber.org/zap v1.24.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.27.0 // indirect golang.org/x/sys v0.4.0 // indirect golang.org/x/text v0.6.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/main.go b/main.go index e0240e8..a540ca8 100644 --- a/main.go +++ b/main.go @@ -1,24 +1,25 @@ package main import ( - "flag" + "fmt" "git.makemake.in/kzkzzzz/mycommon/myconf" "git.makemake.in/kzkzzzz/mycommon/mylog" + "github.com/spf13/pflag" "proxyport/app" ) -var configPath string - func main() { - flag.StringVar(&configPath, "c", "config.toml", "配置文件路径") - flag.Parse() + pflag.String("conf", "config.toml", "config file path") + myconf.LoadFlag() cfg := mylog.DefaultConfig cfg.ConsoleWriter = nil cfg.NeedLogFile = true mylog.Init("debug", cfg) - myconf.Init(configPath, &app.ProxyMap) + myconf.LoadFileTo(myconf.Conf().GetString("conf"), &app.Conf) defer mylog.Flush() + + fmt.Printf("%+v\n", app.Conf) app.Run() }