mirror of
				https://github.com/onyx-and-iris/q3rcon-proxy.git
				synced 2025-10-30 20:31:48 +00:00 
			
		
		
		
	remove init function\
remove global vars proxies, host
This commit is contained in:
		
							parent
							
								
									2fc0f7a74f
								
							
						
					
					
						commit
						3d1c8f90f3
					
				| @ -3,7 +3,7 @@ package main | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"strconv" | ||||
| 	"slices" | ||||
| 	"strings" | ||||
| 
 | ||||
| 	log "github.com/sirupsen/logrus" | ||||
| @ -11,7 +11,33 @@ import ( | ||||
| 	"github.com/onyx-and-iris/q3rcon-proxy/pkg/udpproxy" | ||||
| ) | ||||
| 
 | ||||
| func start(proxy string) { | ||||
| func main() { | ||||
| 	logLevel, err := getEnvInt("Q3RCON_LOGLEVEL") | ||||
| 	if err != nil { | ||||
| 		log.Fatalf("unable to parse Q3RCON_LEVEL: %s", err.Error()) | ||||
| 	} | ||||
| 	if slices.Contains(log.AllLevels, log.Level(logLevel)) { | ||||
| 		log.SetLevel(log.Level(logLevel)) | ||||
| 	} | ||||
| 
 | ||||
| 	proxies := os.Getenv("Q3RCON_PROXY") | ||||
| 	if proxies == "" { | ||||
| 		log.Fatal("env Q3RCON_PROXY required") | ||||
| 	} | ||||
| 
 | ||||
| 	host := os.Getenv("Q3RCON_HOST") | ||||
| 	if host == "" { | ||||
| 		host = "0.0.0.0" | ||||
| 	} | ||||
| 
 | ||||
| 	for _, proxy := range strings.Split(proxies, ";") { | ||||
| 		go start(host, proxy) | ||||
| 	} | ||||
| 
 | ||||
| 	<-make(chan int) | ||||
| } | ||||
| 
 | ||||
| func start(host, proxy string) { | ||||
| 	port, target := func() (string, string) { | ||||
| 		x := strings.Split(proxy, ":") | ||||
| 		return x[0], x[1] | ||||
| @ -26,51 +52,3 @@ func start(proxy string) { | ||||
| 
 | ||||
| 	log.Fatal(c.ListenAndServe()) | ||||
| } | ||||
| 
 | ||||
| var ( | ||||
| 	proxies, host string | ||||
| ) | ||||
| 
 | ||||
| func getenvInt(key string) (int, error) { | ||||
| 	s := os.Getenv(key) | ||||
| 	if s == "" { | ||||
| 		return 0, nil | ||||
| 	} | ||||
| 	v, err := strconv.Atoi(s) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return v, nil | ||||
| } | ||||
| 
 | ||||
| func init() { | ||||
| 	proxies = os.Getenv("Q3RCON_PROXY") | ||||
| 	if proxies == "" { | ||||
| 		log.Fatal("env Q3RCON_PROXY required") | ||||
| 	} | ||||
| 
 | ||||
| 	host = os.Getenv("Q3RCON_HOST") | ||||
| 	if host == "" { | ||||
| 		host = "0.0.0.0" | ||||
| 	} | ||||
| 
 | ||||
| 	debug, err := getenvInt("Q3RCON_DEBUG") | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| 
 | ||||
| 	if debug == 1 { | ||||
| 		log.SetLevel(log.DebugLevel) | ||||
| 	} else { | ||||
| 		log.SetLevel(log.InfoLevel) | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| func main() { | ||||
| 	for _, proxy := range strings.Split(proxies, ";") { | ||||
| 		go start(proxy) | ||||
| 	} | ||||
| 
 | ||||
| 	<-make(chan int) | ||||
| } | ||||
|  | ||||
							
								
								
									
										18
									
								
								cmd/q3rcon-proxy/util.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								cmd/q3rcon-proxy/util.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| package main | ||||
| 
 | ||||
| import ( | ||||
| 	"os" | ||||
| 	"strconv" | ||||
| ) | ||||
| 
 | ||||
| func getEnvInt(key string) (int, error) { | ||||
| 	s := os.Getenv(key) | ||||
| 	if s == "" { | ||||
| 		return 0, nil | ||||
| 	} | ||||
| 	v, err := strconv.Atoi(s) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return v, nil | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user