v2
lzf 2024-06-24 14:24:35 +08:00
parent fd06bc2510
commit e4c9049924
5 changed files with 24 additions and 18 deletions

5
.gitignore vendored
View File

@ -1,3 +1,6 @@
.idea .idea
bin bin
go.sum go.sum
config.toml
temp
logs

View File

@ -1,7 +1,9 @@
package app package app
type ( type (
Conf map[string]ProxyItem config struct {
Proxy map[string]ProxyItem
}
ProxyItem struct { ProxyItem struct {
RemoteAddr []string RemoteAddr []string
@ -9,4 +11,4 @@ type (
} }
) )
var ProxyMap = make(Conf) var Conf = &config{}

View File

@ -2,6 +2,7 @@ package app
import ( import (
"context" "context"
"fmt"
"git.makemake.in/kzkzzzz/mycommon/mylog" "git.makemake.in/kzkzzzz/mycommon/mylog"
"io" "io"
"math/rand" "math/rand"
@ -19,9 +20,7 @@ var (
) )
func Run() { func Run() {
rand.Seed(time.Now().UnixNano()) for name, item := range Conf.Proxy {
for name, item := range ProxyMap {
go listenTcp(name, item) go listenTcp(name, item)
} }
@ -38,7 +37,7 @@ func Run() {
} }
func listenTcp(name string, item ProxyItem) { func listenTcp(name string, item ProxyItem) {
fmt.Printf("%+v\n", item.LocalAddr)
listen, err := net.Listen("tcp", item.LocalAddr) listen, err := net.Listen("tcp", item.LocalAddr)
if err != nil { if err != nil {
mylog.Errorf("[%s] listen err: %s", name, err) mylog.Errorf("[%s] listen err: %s", name, err)

11
go.mod
View File

@ -2,7 +2,10 @@ module proxyport
go 1.18 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 ( require (
github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect
@ -14,12 +17,10 @@ require (
github.com/spf13/afero v1.9.3 // indirect github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.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/spf13/viper v1.14.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect github.com/subosito/gotenv v1.4.2 // indirect
go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.11.0 // indirect
go.uber.org/multierr v1.9.0 // indirect go.uber.org/zap v1.27.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/sys v0.4.0 // indirect golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect golang.org/x/text v0.6.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect

13
main.go
View File

@ -1,24 +1,25 @@
package main package main
import ( import (
"flag" "fmt"
"git.makemake.in/kzkzzzz/mycommon/myconf" "git.makemake.in/kzkzzzz/mycommon/myconf"
"git.makemake.in/kzkzzzz/mycommon/mylog" "git.makemake.in/kzkzzzz/mycommon/mylog"
"github.com/spf13/pflag"
"proxyport/app" "proxyport/app"
) )
var configPath string
func main() { func main() {
flag.StringVar(&configPath, "c", "config.toml", "配置文件路径") pflag.String("conf", "config.toml", "config file path")
flag.Parse() myconf.LoadFlag()
cfg := mylog.DefaultConfig cfg := mylog.DefaultConfig
cfg.ConsoleWriter = nil cfg.ConsoleWriter = nil
cfg.NeedLogFile = true cfg.NeedLogFile = true
mylog.Init("debug", cfg) mylog.Init("debug", cfg)
myconf.Init(configPath, &app.ProxyMap) myconf.LoadFileTo(myconf.Conf().GetString("conf"), &app.Conf)
defer mylog.Flush() defer mylog.Flush()
fmt.Printf("%+v\n", app.Conf)
app.Run() app.Run()
} }