Browse Source

feat: proxy options in config file

v1.x.x
dnomd343 2 years ago
parent
commit
310cbd6cb6
  1. 14
      src/config.go
  2. 3
      src/load.go
  3. 28
      src/main.go
  4. 16
      test.yml

14
src/config.go

@ -27,6 +27,13 @@ type netConfig struct {
}
type Config struct {
Proxy struct {
Sniff bool `yaml:"sniff"`
Redirect bool `yaml:"redirect"`
Http map[string]int `yaml:"http"`
Socks map[string]int `yaml:"socks"`
AddOn []interface{} `yaml:"addon"`
}
Network struct {
DNS []string `yaml:"dns"` // system dns server
ByPass []string `yaml:"bypass"` // cidr bypass list
@ -118,4 +125,11 @@ func loadConfig(rawConfig []byte) {
panic("Invalid IPv6 gateway -> " + v6Gateway)
}
log.Infof("IPv6 -> address = %s | gateway = %s", v6Address, v6Gateway)
httpInbounds = config.Proxy.Http
log.Infof("Http inbounds -> %v", httpInbounds)
socksInbounds = config.Proxy.Socks
log.Infof("Socks inbounds -> %v", socksInbounds)
addOnInbounds = config.Proxy.AddOn
log.Infof("Add-on inbounds -> %v", addOnInbounds)
}

3
src/load.go

@ -210,6 +210,9 @@ func loadProxy(configDir string, exposeDir string) {
for tag, port := range socksInbounds {
inboundsObject.Inbounds = append(inboundsObject.Inbounds, loadSocksProxy(tag, port, sniffObject))
}
for _, addon := range addOnInbounds {
inboundsObject.Inbounds = append(inboundsObject.Inbounds, addon)
}
inboundsConfig, _ := json.MarshalIndent(inboundsObject, "", " ") // json encode
saveConfig(configDir, "inbounds", string(inboundsConfig), true)

28
src/main.go

@ -1,8 +1,8 @@
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
"os"
)
var logLevel = "warning"
@ -12,27 +12,23 @@ var v6TProxyPort = 7289
var enableSniff = false
var enableRedirect = true
var httpInbounds = make(map[string]int)
var socksInbounds = make(map[string]int)
var httpInbounds map[string]int
var socksInbounds map[string]int
var addOnInbounds []interface{}
func main() {
log.SetLevel(log.DebugLevel)
log.Warning("XProxy start")
httpInbounds["ipv4"] = 1084
httpInbounds["ipv6"] = 1086
fmt.Println(httpInbounds)
socksInbounds["nodeA"] = 1681
socksInbounds["nodeB"] = 1682
socksInbounds["nodeC"] = 1683
fmt.Println(socksInbounds)
content, err := os.ReadFile("test.yml")
if err != nil {
panic(err)
}
loadConfig(content)
//fmt.Println(httpInbounds)
//fmt.Println(socksInbounds)
//fmt.Println(addOnInbounds)
loadProxy("/etc/xproxy/config", "/xproxy")
//content, err := os.ReadFile("test.yml")
//if err != nil {
// panic(err)
//}
//loadConfig(content)
}

16
test.yml

@ -2,12 +2,18 @@ proxy:
sniff: true
redirect: true
http:
- ipv4: 1084
- ipv6: 1086
ipv4: 1084
ipv6: 1086
socks:
- nodeA: 1681
- nodeB: 1682
- nodeC: 1683
nodeA: 1681
nodeB: 1682
nodeC: 1683
addon:
- tag: metrics
port: 9090
protocol: dokodemo-door
settings:
address: 127.0.0.1
network:
dns:

Loading…
Cancel
Save