Files
SingBox-Gopanel/internal/protocol/singbox.go
CN-JS-HuiBai 1ed31b9292
All checks were successful
build / build (api, amd64, linux) (push) Successful in -47s
build / build (api, arm64, linux) (push) Successful in -48s
build / build (api.exe, amd64, windows) (push) Successful in -47s
first commit
2026-04-17 09:49:16 +08:00

43 lines
962 B
Go

package protocol
import (
"encoding/json"
"xboard-go/internal/model"
)
type SingBoxConfig struct {
Outbounds []map[string]interface{} `json:"outbounds"`
}
func GenerateSingBox(servers []model.Server, user model.User) (string, error) {
config := SingBoxConfig{
Outbounds: []map[string]interface{}{},
}
// Add selector outbound
selector := map[string]interface{}{
"type": "selector",
"tag": "Proxy",
"outbounds": []string{},
}
for _, s := range servers {
outbound := map[string]interface{}{
"type": s.Type,
"tag": s.Name,
"server": s.Host,
"server_port": s.Port,
}
// Add protocol-specific settings
// ... logic to handle VMess, Shadowsocks, etc.
config.Outbounds = append(config.Outbounds, outbound)
selector["outbounds"] = append(selector["outbounds"].([]string), s.Name)
}
config.Outbounds = append(config.Outbounds, selector)
data, err := json.MarshalIndent(config, "", " ")
return string(data), err
}