update
							parent
							
								
									fd06bc2510
								
							
						
					
					
						commit
						e4c9049924
					
				| 
						 | 
				
			
			@ -1,3 +1,6 @@
 | 
			
		|||
.idea
 | 
			
		||||
bin
 | 
			
		||||
go.sum
 | 
			
		||||
go.sum
 | 
			
		||||
config.toml
 | 
			
		||||
temp
 | 
			
		||||
logs
 | 
			
		||||
| 
						 | 
				
			
			@ -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{}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										11
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										11
									
								
								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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										13
									
								
								main.go
								
								
								
								
							
							
						
						
									
										13
									
								
								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()
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue