Refactor: Use any instead of interface{}

This commit is contained in:
mhsanaei 2025-03-12 20:13:51 +01:00
parent 280a22b57d
commit 0bde51b91e
No known key found for this signature in database
GPG key ID: D875CD086CF668A0
19 changed files with 267 additions and 280 deletions

View file

@ -26,7 +26,7 @@ const (
) )
func initModels() error { func initModels() error {
models := []interface{}{ models := []any{
&model.User{}, &model.User{},
&model.Inbound{}, &model.Inbound{},
&model.OutboundTraffics{}, &model.OutboundTraffics{},

View file

@ -47,52 +47,52 @@ func InitLogger(level logging.Level) {
logger = newLogger logger = newLogger
} }
func Debug(args ...interface{}) { func Debug(args ...any) {
logger.Debug(args...) logger.Debug(args...)
addToBuffer("DEBUG", fmt.Sprint(args...)) addToBuffer("DEBUG", fmt.Sprint(args...))
} }
func Debugf(format string, args ...interface{}) { func Debugf(format string, args ...any) {
logger.Debugf(format, args...) logger.Debugf(format, args...)
addToBuffer("DEBUG", fmt.Sprintf(format, args...)) addToBuffer("DEBUG", fmt.Sprintf(format, args...))
} }
func Info(args ...interface{}) { func Info(args ...any) {
logger.Info(args...) logger.Info(args...)
addToBuffer("INFO", fmt.Sprint(args...)) addToBuffer("INFO", fmt.Sprint(args...))
} }
func Infof(format string, args ...interface{}) { func Infof(format string, args ...any) {
logger.Infof(format, args...) logger.Infof(format, args...)
addToBuffer("INFO", fmt.Sprintf(format, args...)) addToBuffer("INFO", fmt.Sprintf(format, args...))
} }
func Notice(args ...interface{}) { func Notice(args ...any) {
logger.Notice(args...) logger.Notice(args...)
addToBuffer("NOTICE", fmt.Sprint(args...)) addToBuffer("NOTICE", fmt.Sprint(args...))
} }
func Noticef(format string, args ...interface{}) { func Noticef(format string, args ...any) {
logger.Noticef(format, args...) logger.Noticef(format, args...)
addToBuffer("NOTICE", fmt.Sprintf(format, args...)) addToBuffer("NOTICE", fmt.Sprintf(format, args...))
} }
func Warning(args ...interface{}) { func Warning(args ...any) {
logger.Warning(args...) logger.Warning(args...)
addToBuffer("WARNING", fmt.Sprint(args...)) addToBuffer("WARNING", fmt.Sprint(args...))
} }
func Warningf(format string, args ...interface{}) { func Warningf(format string, args ...any) {
logger.Warningf(format, args...) logger.Warningf(format, args...)
addToBuffer("WARNING", fmt.Sprintf(format, args...)) addToBuffer("WARNING", fmt.Sprintf(format, args...))
} }
func Error(args ...interface{}) { func Error(args ...any) {
logger.Error(args...) logger.Error(args...)
addToBuffer("ERROR", fmt.Sprint(args...)) addToBuffer("ERROR", fmt.Sprint(args...))
} }
func Errorf(format string, args ...interface{}) { func Errorf(format string, args ...any) {
logger.Errorf(format, args...) logger.Errorf(format, args...)
addToBuffer("ERROR", fmt.Sprintf(format, args...)) addToBuffer("ERROR", fmt.Sprintf(format, args...))
} }

View file

@ -18,7 +18,7 @@ import (
var defaultJson string var defaultJson string
type SubJsonService struct { type SubJsonService struct {
configJson map[string]interface{} configJson map[string]any
defaultOutbounds []json_util.RawMessage defaultOutbounds []json_util.RawMessage
fragment string fragment string
noises string noises string
@ -29,10 +29,10 @@ type SubJsonService struct {
} }
func NewSubJsonService(fragment string, noises string, mux string, rules string, subService *SubService) *SubJsonService { func NewSubJsonService(fragment string, noises string, mux string, rules string, subService *SubService) *SubJsonService {
var configJson map[string]interface{} var configJson map[string]any
var defaultOutbounds []json_util.RawMessage var defaultOutbounds []json_util.RawMessage
json.Unmarshal([]byte(defaultJson), &configJson) json.Unmarshal([]byte(defaultJson), &configJson)
if outboundSlices, ok := configJson["outbounds"].([]interface{}); ok { if outboundSlices, ok := configJson["outbounds"].([]any); ok {
for _, defaultOutbound := range outboundSlices { for _, defaultOutbound := range outboundSlices {
jsonBytes, _ := json.Marshal(defaultOutbound) jsonBytes, _ := json.Marshal(defaultOutbound)
defaultOutbounds = append(defaultOutbounds, jsonBytes) defaultOutbounds = append(defaultOutbounds, jsonBytes)
@ -40,9 +40,9 @@ func NewSubJsonService(fragment string, noises string, mux string, rules string,
} }
if rules != "" { if rules != "" {
var newRules []interface{} var newRules []any
routing, _ := configJson["routing"].(map[string]interface{}) routing, _ := configJson["routing"].(map[string]any)
defaultRules, _ := routing["rules"].([]interface{}) defaultRules, _ := routing["rules"].([]any)
json.Unmarshal([]byte(rules), &newRules) json.Unmarshal([]byte(rules), &newRules)
defaultRules = append(newRules, defaultRules...) defaultRules = append(newRules, defaultRules...)
routing["rules"] = defaultRules routing["rules"] = defaultRules
@ -148,10 +148,10 @@ func (s *SubJsonService) getConfig(inbound *model.Inbound, client model.Client,
var newJsonArray []json_util.RawMessage var newJsonArray []json_util.RawMessage
stream := s.streamData(inbound.StreamSettings) stream := s.streamData(inbound.StreamSettings)
externalProxies, ok := stream["externalProxy"].([]interface{}) externalProxies, ok := stream["externalProxy"].([]any)
if !ok || len(externalProxies) == 0 { if !ok || len(externalProxies) == 0 {
externalProxies = []interface{}{ externalProxies = []any{
map[string]interface{}{ map[string]any{
"forceTls": "same", "forceTls": "same",
"dest": host, "dest": host,
"port": float64(inbound.Port), "port": float64(inbound.Port),
@ -163,7 +163,7 @@ func (s *SubJsonService) getConfig(inbound *model.Inbound, client model.Client,
delete(stream, "externalProxy") delete(stream, "externalProxy")
for _, ep := range externalProxies { for _, ep := range externalProxies {
extPrxy := ep.(map[string]interface{}) extPrxy := ep.(map[string]any)
inbound.Listen = extPrxy["dest"].(string) inbound.Listen = extPrxy["dest"].(string)
inbound.Port = int(extPrxy["port"].(float64)) inbound.Port = int(extPrxy["port"].(float64))
newStream := stream newStream := stream
@ -171,7 +171,7 @@ func (s *SubJsonService) getConfig(inbound *model.Inbound, client model.Client,
case "tls": case "tls":
if newStream["security"] != "tls" { if newStream["security"] != "tls" {
newStream["security"] = "tls" newStream["security"] = "tls"
newStream["tslSettings"] = map[string]interface{}{} newStream["tslSettings"] = map[string]any{}
} }
case "none": case "none":
if newStream["security"] != "none" { if newStream["security"] != "none" {
@ -191,7 +191,7 @@ func (s *SubJsonService) getConfig(inbound *model.Inbound, client model.Client,
} }
newOutbounds = append(newOutbounds, s.defaultOutbounds...) newOutbounds = append(newOutbounds, s.defaultOutbounds...)
newConfigJson := make(map[string]interface{}) newConfigJson := make(map[string]any)
for key, value := range s.configJson { for key, value := range s.configJson {
newConfigJson[key] = value newConfigJson[key] = value
} }
@ -205,14 +205,14 @@ func (s *SubJsonService) getConfig(inbound *model.Inbound, client model.Client,
return newJsonArray return newJsonArray
} }
func (s *SubJsonService) streamData(stream string) map[string]interface{} { func (s *SubJsonService) streamData(stream string) map[string]any {
var streamSettings map[string]interface{} var streamSettings map[string]any
json.Unmarshal([]byte(stream), &streamSettings) json.Unmarshal([]byte(stream), &streamSettings)
security, _ := streamSettings["security"].(string) security, _ := streamSettings["security"].(string)
if security == "tls" { if security == "tls" {
streamSettings["tlsSettings"] = s.tlsData(streamSettings["tlsSettings"].(map[string]interface{})) streamSettings["tlsSettings"] = s.tlsData(streamSettings["tlsSettings"].(map[string]any))
} else if security == "reality" { } else if security == "reality" {
streamSettings["realitySettings"] = s.realityData(streamSettings["realitySettings"].(map[string]interface{})) streamSettings["realitySettings"] = s.realityData(streamSettings["realitySettings"].(map[string]any))
} }
delete(streamSettings, "sockopt") delete(streamSettings, "sockopt")
@ -233,17 +233,17 @@ func (s *SubJsonService) streamData(stream string) map[string]interface{} {
return streamSettings return streamSettings
} }
func (s *SubJsonService) removeAcceptProxy(setting interface{}) map[string]interface{} { func (s *SubJsonService) removeAcceptProxy(setting any) map[string]any {
netSettings, ok := setting.(map[string]interface{}) netSettings, ok := setting.(map[string]any)
if ok { if ok {
delete(netSettings, "acceptProxyProtocol") delete(netSettings, "acceptProxyProtocol")
} }
return netSettings return netSettings
} }
func (s *SubJsonService) tlsData(tData map[string]interface{}) map[string]interface{} { func (s *SubJsonService) tlsData(tData map[string]any) map[string]any {
tlsData := make(map[string]interface{}, 1) tlsData := make(map[string]any, 1)
tlsClientSettings, _ := tData["settings"].(map[string]interface{}) tlsClientSettings, _ := tData["settings"].(map[string]any)
tlsData["serverName"] = tData["serverName"] tlsData["serverName"] = tData["serverName"]
tlsData["alpn"] = tData["alpn"] tlsData["alpn"] = tData["alpn"]
@ -256,9 +256,9 @@ func (s *SubJsonService) tlsData(tData map[string]interface{}) map[string]interf
return tlsData return tlsData
} }
func (s *SubJsonService) realityData(rData map[string]interface{}) map[string]interface{} { func (s *SubJsonService) realityData(rData map[string]any) map[string]any {
rltyData := make(map[string]interface{}, 1) rltyData := make(map[string]any, 1)
rltyClientSettings, _ := rData["settings"].(map[string]interface{}) rltyClientSettings, _ := rData["settings"].(map[string]any)
rltyData["show"] = false rltyData["show"] = false
rltyData["publicKey"] = rltyClientSettings["publicKey"] rltyData["publicKey"] = rltyClientSettings["publicKey"]
@ -266,13 +266,13 @@ func (s *SubJsonService) realityData(rData map[string]interface{}) map[string]in
// Set random data // Set random data
rltyData["spiderX"] = "/" + random.Seq(15) rltyData["spiderX"] = "/" + random.Seq(15)
shortIds, ok := rData["shortIds"].([]interface{}) shortIds, ok := rData["shortIds"].([]any)
if ok && len(shortIds) > 0 { if ok && len(shortIds) > 0 {
rltyData["shortId"] = shortIds[random.Num(len(shortIds))].(string) rltyData["shortId"] = shortIds[random.Num(len(shortIds))].(string)
} else { } else {
rltyData["shortId"] = "" rltyData["shortId"] = ""
} }
serverNames, ok := rData["serverNames"].([]interface{}) serverNames, ok := rData["serverNames"].([]any)
if ok && len(serverNames) > 0 { if ok && len(serverNames) > 0 {
rltyData["serverName"] = serverNames[random.Num(len(serverNames))].(string) rltyData["serverName"] = serverNames[random.Num(len(serverNames))].(string)
} else { } else {
@ -329,7 +329,7 @@ func (s *SubJsonService) genServer(inbound *model.Inbound, streamSettings json_u
} }
if inbound.Protocol == model.Shadowsocks { if inbound.Protocol == model.Shadowsocks {
var inboundSettings map[string]interface{} var inboundSettings map[string]any
json.Unmarshal([]byte(inbound.Settings), &inboundSettings) json.Unmarshal([]byte(inbound.Settings), &inboundSettings)
method, _ := inboundSettings["method"].(string) method, _ := inboundSettings["method"].(string)
serverData[0].Method = method serverData[0].Method = method
@ -357,12 +357,12 @@ func (s *SubJsonService) genServer(inbound *model.Inbound, streamSettings json_u
} }
type Outbound struct { type Outbound struct {
Protocol string `json:"protocol"` Protocol string `json:"protocol"`
Tag string `json:"tag"` Tag string `json:"tag"`
StreamSettings json_util.RawMessage `json:"streamSettings"` StreamSettings json_util.RawMessage `json:"streamSettings"`
Mux json_util.RawMessage `json:"mux,omitempty"` Mux json_util.RawMessage `json:"mux,omitempty"`
ProxySettings map[string]interface{} `json:"proxySettings,omitempty"` ProxySettings map[string]any `json:"proxySettings,omitempty"`
Settings OutboundSettings `json:"settings,omitempty"` Settings OutboundSettings `json:"settings,omitempty"`
} }
type OutboundSettings struct { type OutboundSettings struct {

View file

@ -141,9 +141,9 @@ func (s *SubService) getFallbackMaster(dest string, streamSettings string) (stri
return "", 0, "", err return "", 0, "", err
} }
var stream map[string]interface{} var stream map[string]any
json.Unmarshal([]byte(streamSettings), &stream) json.Unmarshal([]byte(streamSettings), &stream)
var masterStream map[string]interface{} var masterStream map[string]any
json.Unmarshal([]byte(inbound.StreamSettings), &masterStream) json.Unmarshal([]byte(inbound.StreamSettings), &masterStream)
stream["security"] = masterStream["security"] stream["security"] = masterStream["security"]
stream["tlsSettings"] = masterStream["tlsSettings"] stream["tlsSettings"] = masterStream["tlsSettings"]
@ -171,66 +171,66 @@ func (s *SubService) genVmessLink(inbound *model.Inbound, email string) string {
if inbound.Protocol != model.VMESS { if inbound.Protocol != model.VMESS {
return "" return ""
} }
obj := map[string]interface{}{ obj := map[string]any{
"v": "2", "v": "2",
"add": s.address, "add": s.address,
"port": inbound.Port, "port": inbound.Port,
"type": "none", "type": "none",
} }
var stream map[string]interface{} var stream map[string]any
json.Unmarshal([]byte(inbound.StreamSettings), &stream) json.Unmarshal([]byte(inbound.StreamSettings), &stream)
network, _ := stream["network"].(string) network, _ := stream["network"].(string)
obj["net"] = network obj["net"] = network
switch network { switch network {
case "tcp": case "tcp":
tcp, _ := stream["tcpSettings"].(map[string]interface{}) tcp, _ := stream["tcpSettings"].(map[string]any)
header, _ := tcp["header"].(map[string]interface{}) header, _ := tcp["header"].(map[string]any)
typeStr, _ := header["type"].(string) typeStr, _ := header["type"].(string)
obj["type"] = typeStr obj["type"] = typeStr
if typeStr == "http" { if typeStr == "http" {
request := header["request"].(map[string]interface{}) request := header["request"].(map[string]any)
requestPath, _ := request["path"].([]interface{}) requestPath, _ := request["path"].([]any)
obj["path"] = requestPath[0].(string) obj["path"] = requestPath[0].(string)
headers, _ := request["headers"].(map[string]interface{}) headers, _ := request["headers"].(map[string]any)
obj["host"] = searchHost(headers) obj["host"] = searchHost(headers)
} }
case "kcp": case "kcp":
kcp, _ := stream["kcpSettings"].(map[string]interface{}) kcp, _ := stream["kcpSettings"].(map[string]any)
header, _ := kcp["header"].(map[string]interface{}) header, _ := kcp["header"].(map[string]any)
obj["type"], _ = header["type"].(string) obj["type"], _ = header["type"].(string)
obj["path"], _ = kcp["seed"].(string) obj["path"], _ = kcp["seed"].(string)
case "ws": case "ws":
ws, _ := stream["wsSettings"].(map[string]interface{}) ws, _ := stream["wsSettings"].(map[string]any)
obj["path"] = ws["path"].(string) obj["path"] = ws["path"].(string)
if host, ok := ws["host"].(string); ok && len(host) > 0 { if host, ok := ws["host"].(string); ok && len(host) > 0 {
obj["host"] = host obj["host"] = host
} else { } else {
headers, _ := ws["headers"].(map[string]interface{}) headers, _ := ws["headers"].(map[string]any)
obj["host"] = searchHost(headers) obj["host"] = searchHost(headers)
} }
case "grpc": case "grpc":
grpc, _ := stream["grpcSettings"].(map[string]interface{}) grpc, _ := stream["grpcSettings"].(map[string]any)
obj["path"] = grpc["serviceName"].(string) obj["path"] = grpc["serviceName"].(string)
obj["authority"] = grpc["authority"].(string) obj["authority"] = grpc["authority"].(string)
if grpc["multiMode"].(bool) { if grpc["multiMode"].(bool) {
obj["type"] = "multi" obj["type"] = "multi"
} }
case "httpupgrade": case "httpupgrade":
httpupgrade, _ := stream["httpupgradeSettings"].(map[string]interface{}) httpupgrade, _ := stream["httpupgradeSettings"].(map[string]any)
obj["path"] = httpupgrade["path"].(string) obj["path"] = httpupgrade["path"].(string)
if host, ok := httpupgrade["host"].(string); ok && len(host) > 0 { if host, ok := httpupgrade["host"].(string); ok && len(host) > 0 {
obj["host"] = host obj["host"] = host
} else { } else {
headers, _ := httpupgrade["headers"].(map[string]interface{}) headers, _ := httpupgrade["headers"].(map[string]any)
obj["host"] = searchHost(headers) obj["host"] = searchHost(headers)
} }
case "xhttp": case "xhttp":
xhttp, _ := stream["xhttpSettings"].(map[string]interface{}) xhttp, _ := stream["xhttpSettings"].(map[string]any)
obj["path"] = xhttp["path"].(string) obj["path"] = xhttp["path"].(string)
if host, ok := xhttp["host"].(string); ok && len(host) > 0 { if host, ok := xhttp["host"].(string); ok && len(host) > 0 {
obj["host"] = host obj["host"] = host
} else { } else {
headers, _ := xhttp["headers"].(map[string]interface{}) headers, _ := xhttp["headers"].(map[string]any)
obj["host"] = searchHost(headers) obj["host"] = searchHost(headers)
} }
obj["mode"] = xhttp["mode"].(string) obj["mode"] = xhttp["mode"].(string)
@ -238,8 +238,8 @@ func (s *SubService) genVmessLink(inbound *model.Inbound, email string) string {
security, _ := stream["security"].(string) security, _ := stream["security"].(string)
obj["tls"] = security obj["tls"] = security
if security == "tls" { if security == "tls" {
tlsSetting, _ := stream["tlsSettings"].(map[string]interface{}) tlsSetting, _ := stream["tlsSettings"].(map[string]any)
alpns, _ := tlsSetting["alpn"].([]interface{}) alpns, _ := tlsSetting["alpn"].([]any)
if len(alpns) > 0 { if len(alpns) > 0 {
var alpn []string var alpn []string
for _, a := range alpns { for _, a := range alpns {
@ -273,14 +273,14 @@ func (s *SubService) genVmessLink(inbound *model.Inbound, email string) string {
obj["id"] = clients[clientIndex].ID obj["id"] = clients[clientIndex].ID
obj["scy"] = clients[clientIndex].Security obj["scy"] = clients[clientIndex].Security
externalProxies, _ := stream["externalProxy"].([]interface{}) externalProxies, _ := stream["externalProxy"].([]any)
if len(externalProxies) > 0 { if len(externalProxies) > 0 {
links := "" links := ""
for index, externalProxy := range externalProxies { for index, externalProxy := range externalProxies {
ep, _ := externalProxy.(map[string]interface{}) ep, _ := externalProxy.(map[string]any)
newSecurity, _ := ep["forceTls"].(string) newSecurity, _ := ep["forceTls"].(string)
newObj := map[string]interface{}{} newObj := map[string]any{}
for key, value := range obj { for key, value := range obj {
if !(newSecurity == "none" && (key == "alpn" || key == "sni" || key == "fp" || key == "allowInsecure")) { if !(newSecurity == "none" && (key == "alpn" || key == "sni" || key == "fp" || key == "allowInsecure")) {
newObj[key] = value newObj[key] = value
@ -313,7 +313,7 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string {
if inbound.Protocol != model.VLESS { if inbound.Protocol != model.VLESS {
return "" return ""
} }
var stream map[string]interface{} var stream map[string]any
json.Unmarshal([]byte(inbound.StreamSettings), &stream) json.Unmarshal([]byte(inbound.StreamSettings), &stream)
clients, _ := s.inboundService.GetClients(inbound) clients, _ := s.inboundService.GetClients(inbound)
clientIndex := -1 clientIndex := -1
@ -331,54 +331,54 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string {
switch streamNetwork { switch streamNetwork {
case "tcp": case "tcp":
tcp, _ := stream["tcpSettings"].(map[string]interface{}) tcp, _ := stream["tcpSettings"].(map[string]any)
header, _ := tcp["header"].(map[string]interface{}) header, _ := tcp["header"].(map[string]any)
typeStr, _ := header["type"].(string) typeStr, _ := header["type"].(string)
if typeStr == "http" { if typeStr == "http" {
request := header["request"].(map[string]interface{}) request := header["request"].(map[string]any)
requestPath, _ := request["path"].([]interface{}) requestPath, _ := request["path"].([]any)
params["path"] = requestPath[0].(string) params["path"] = requestPath[0].(string)
headers, _ := request["headers"].(map[string]interface{}) headers, _ := request["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
params["headerType"] = "http" params["headerType"] = "http"
} }
case "kcp": case "kcp":
kcp, _ := stream["kcpSettings"].(map[string]interface{}) kcp, _ := stream["kcpSettings"].(map[string]any)
header, _ := kcp["header"].(map[string]interface{}) header, _ := kcp["header"].(map[string]any)
params["headerType"] = header["type"].(string) params["headerType"] = header["type"].(string)
params["seed"] = kcp["seed"].(string) params["seed"] = kcp["seed"].(string)
case "ws": case "ws":
ws, _ := stream["wsSettings"].(map[string]interface{}) ws, _ := stream["wsSettings"].(map[string]any)
params["path"] = ws["path"].(string) params["path"] = ws["path"].(string)
if host, ok := ws["host"].(string); ok && len(host) > 0 { if host, ok := ws["host"].(string); ok && len(host) > 0 {
params["host"] = host params["host"] = host
} else { } else {
headers, _ := ws["headers"].(map[string]interface{}) headers, _ := ws["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
} }
case "grpc": case "grpc":
grpc, _ := stream["grpcSettings"].(map[string]interface{}) grpc, _ := stream["grpcSettings"].(map[string]any)
params["serviceName"] = grpc["serviceName"].(string) params["serviceName"] = grpc["serviceName"].(string)
params["authority"], _ = grpc["authority"].(string) params["authority"], _ = grpc["authority"].(string)
if grpc["multiMode"].(bool) { if grpc["multiMode"].(bool) {
params["mode"] = "multi" params["mode"] = "multi"
} }
case "httpupgrade": case "httpupgrade":
httpupgrade, _ := stream["httpupgradeSettings"].(map[string]interface{}) httpupgrade, _ := stream["httpupgradeSettings"].(map[string]any)
params["path"] = httpupgrade["path"].(string) params["path"] = httpupgrade["path"].(string)
if host, ok := httpupgrade["host"].(string); ok && len(host) > 0 { if host, ok := httpupgrade["host"].(string); ok && len(host) > 0 {
params["host"] = host params["host"] = host
} else { } else {
headers, _ := httpupgrade["headers"].(map[string]interface{}) headers, _ := httpupgrade["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
} }
case "xhttp": case "xhttp":
xhttp, _ := stream["xhttpSettings"].(map[string]interface{}) xhttp, _ := stream["xhttpSettings"].(map[string]any)
params["path"] = xhttp["path"].(string) params["path"] = xhttp["path"].(string)
if host, ok := xhttp["host"].(string); ok && len(host) > 0 { if host, ok := xhttp["host"].(string); ok && len(host) > 0 {
params["host"] = host params["host"] = host
} else { } else {
headers, _ := xhttp["headers"].(map[string]interface{}) headers, _ := xhttp["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
} }
params["mode"] = xhttp["mode"].(string) params["mode"] = xhttp["mode"].(string)
@ -386,8 +386,8 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string {
security, _ := stream["security"].(string) security, _ := stream["security"].(string)
if security == "tls" { if security == "tls" {
params["security"] = "tls" params["security"] = "tls"
tlsSetting, _ := stream["tlsSettings"].(map[string]interface{}) tlsSetting, _ := stream["tlsSettings"].(map[string]any)
alpns, _ := tlsSetting["alpn"].([]interface{}) alpns, _ := tlsSetting["alpn"].([]any)
var alpn []string var alpn []string
for _, a := range alpns { for _, a := range alpns {
alpn = append(alpn, a.(string)) alpn = append(alpn, a.(string))
@ -418,18 +418,18 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string {
if security == "reality" { if security == "reality" {
params["security"] = "reality" params["security"] = "reality"
realitySetting, _ := stream["realitySettings"].(map[string]interface{}) realitySetting, _ := stream["realitySettings"].(map[string]any)
realitySettings, _ := searchKey(realitySetting, "settings") realitySettings, _ := searchKey(realitySetting, "settings")
if realitySetting != nil { if realitySetting != nil {
if sniValue, ok := searchKey(realitySetting, "serverNames"); ok { if sniValue, ok := searchKey(realitySetting, "serverNames"); ok {
sNames, _ := sniValue.([]interface{}) sNames, _ := sniValue.([]any)
params["sni"] = sNames[random.Num(len(sNames))].(string) params["sni"] = sNames[random.Num(len(sNames))].(string)
} }
if pbkValue, ok := searchKey(realitySettings, "publicKey"); ok { if pbkValue, ok := searchKey(realitySettings, "publicKey"); ok {
params["pbk"], _ = pbkValue.(string) params["pbk"], _ = pbkValue.(string)
} }
if sidValue, ok := searchKey(realitySetting, "shortIds"); ok { if sidValue, ok := searchKey(realitySetting, "shortIds"); ok {
shortIds, _ := sidValue.([]interface{}) shortIds, _ := sidValue.([]any)
params["sid"] = shortIds[random.Num(len(shortIds))].(string) params["sid"] = shortIds[random.Num(len(shortIds))].(string)
} }
if fpValue, ok := searchKey(realitySettings, "fingerprint"); ok { if fpValue, ok := searchKey(realitySettings, "fingerprint"); ok {
@ -449,12 +449,12 @@ func (s *SubService) genVlessLink(inbound *model.Inbound, email string) string {
params["security"] = "none" params["security"] = "none"
} }
externalProxies, _ := stream["externalProxy"].([]interface{}) externalProxies, _ := stream["externalProxy"].([]any)
if len(externalProxies) > 0 { if len(externalProxies) > 0 {
links := "" links := ""
for index, externalProxy := range externalProxies { for index, externalProxy := range externalProxies {
ep, _ := externalProxy.(map[string]interface{}) ep, _ := externalProxy.(map[string]any)
newSecurity, _ := ep["forceTls"].(string) newSecurity, _ := ep["forceTls"].(string)
dest, _ := ep["dest"].(string) dest, _ := ep["dest"].(string)
port := int(ep["port"].(float64)) port := int(ep["port"].(float64))
@ -507,7 +507,7 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
if inbound.Protocol != model.Trojan { if inbound.Protocol != model.Trojan {
return "" return ""
} }
var stream map[string]interface{} var stream map[string]any
json.Unmarshal([]byte(inbound.StreamSettings), &stream) json.Unmarshal([]byte(inbound.StreamSettings), &stream)
clients, _ := s.inboundService.GetClients(inbound) clients, _ := s.inboundService.GetClients(inbound)
clientIndex := -1 clientIndex := -1
@ -525,54 +525,54 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
switch streamNetwork { switch streamNetwork {
case "tcp": case "tcp":
tcp, _ := stream["tcpSettings"].(map[string]interface{}) tcp, _ := stream["tcpSettings"].(map[string]any)
header, _ := tcp["header"].(map[string]interface{}) header, _ := tcp["header"].(map[string]any)
typeStr, _ := header["type"].(string) typeStr, _ := header["type"].(string)
if typeStr == "http" { if typeStr == "http" {
request := header["request"].(map[string]interface{}) request := header["request"].(map[string]any)
requestPath, _ := request["path"].([]interface{}) requestPath, _ := request["path"].([]any)
params["path"] = requestPath[0].(string) params["path"] = requestPath[0].(string)
headers, _ := request["headers"].(map[string]interface{}) headers, _ := request["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
params["headerType"] = "http" params["headerType"] = "http"
} }
case "kcp": case "kcp":
kcp, _ := stream["kcpSettings"].(map[string]interface{}) kcp, _ := stream["kcpSettings"].(map[string]any)
header, _ := kcp["header"].(map[string]interface{}) header, _ := kcp["header"].(map[string]any)
params["headerType"] = header["type"].(string) params["headerType"] = header["type"].(string)
params["seed"] = kcp["seed"].(string) params["seed"] = kcp["seed"].(string)
case "ws": case "ws":
ws, _ := stream["wsSettings"].(map[string]interface{}) ws, _ := stream["wsSettings"].(map[string]any)
params["path"] = ws["path"].(string) params["path"] = ws["path"].(string)
if host, ok := ws["host"].(string); ok && len(host) > 0 { if host, ok := ws["host"].(string); ok && len(host) > 0 {
params["host"] = host params["host"] = host
} else { } else {
headers, _ := ws["headers"].(map[string]interface{}) headers, _ := ws["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
} }
case "grpc": case "grpc":
grpc, _ := stream["grpcSettings"].(map[string]interface{}) grpc, _ := stream["grpcSettings"].(map[string]any)
params["serviceName"] = grpc["serviceName"].(string) params["serviceName"] = grpc["serviceName"].(string)
params["authority"], _ = grpc["authority"].(string) params["authority"], _ = grpc["authority"].(string)
if grpc["multiMode"].(bool) { if grpc["multiMode"].(bool) {
params["mode"] = "multi" params["mode"] = "multi"
} }
case "httpupgrade": case "httpupgrade":
httpupgrade, _ := stream["httpupgradeSettings"].(map[string]interface{}) httpupgrade, _ := stream["httpupgradeSettings"].(map[string]any)
params["path"] = httpupgrade["path"].(string) params["path"] = httpupgrade["path"].(string)
if host, ok := httpupgrade["host"].(string); ok && len(host) > 0 { if host, ok := httpupgrade["host"].(string); ok && len(host) > 0 {
params["host"] = host params["host"] = host
} else { } else {
headers, _ := httpupgrade["headers"].(map[string]interface{}) headers, _ := httpupgrade["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
} }
case "xhttp": case "xhttp":
xhttp, _ := stream["xhttpSettings"].(map[string]interface{}) xhttp, _ := stream["xhttpSettings"].(map[string]any)
params["path"] = xhttp["path"].(string) params["path"] = xhttp["path"].(string)
if host, ok := xhttp["host"].(string); ok && len(host) > 0 { if host, ok := xhttp["host"].(string); ok && len(host) > 0 {
params["host"] = host params["host"] = host
} else { } else {
headers, _ := xhttp["headers"].(map[string]interface{}) headers, _ := xhttp["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
} }
params["mode"] = xhttp["mode"].(string) params["mode"] = xhttp["mode"].(string)
@ -580,8 +580,8 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
security, _ := stream["security"].(string) security, _ := stream["security"].(string)
if security == "tls" { if security == "tls" {
params["security"] = "tls" params["security"] = "tls"
tlsSetting, _ := stream["tlsSettings"].(map[string]interface{}) tlsSetting, _ := stream["tlsSettings"].(map[string]any)
alpns, _ := tlsSetting["alpn"].([]interface{}) alpns, _ := tlsSetting["alpn"].([]any)
var alpn []string var alpn []string
for _, a := range alpns { for _, a := range alpns {
alpn = append(alpn, a.(string)) alpn = append(alpn, a.(string))
@ -608,18 +608,18 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
if security == "reality" { if security == "reality" {
params["security"] = "reality" params["security"] = "reality"
realitySetting, _ := stream["realitySettings"].(map[string]interface{}) realitySetting, _ := stream["realitySettings"].(map[string]any)
realitySettings, _ := searchKey(realitySetting, "settings") realitySettings, _ := searchKey(realitySetting, "settings")
if realitySetting != nil { if realitySetting != nil {
if sniValue, ok := searchKey(realitySetting, "serverNames"); ok { if sniValue, ok := searchKey(realitySetting, "serverNames"); ok {
sNames, _ := sniValue.([]interface{}) sNames, _ := sniValue.([]any)
params["sni"] = sNames[random.Num(len(sNames))].(string) params["sni"] = sNames[random.Num(len(sNames))].(string)
} }
if pbkValue, ok := searchKey(realitySettings, "publicKey"); ok { if pbkValue, ok := searchKey(realitySettings, "publicKey"); ok {
params["pbk"], _ = pbkValue.(string) params["pbk"], _ = pbkValue.(string)
} }
if sidValue, ok := searchKey(realitySetting, "shortIds"); ok { if sidValue, ok := searchKey(realitySetting, "shortIds"); ok {
shortIds, _ := sidValue.([]interface{}) shortIds, _ := sidValue.([]any)
params["sid"] = shortIds[random.Num(len(shortIds))].(string) params["sid"] = shortIds[random.Num(len(shortIds))].(string)
} }
if fpValue, ok := searchKey(realitySettings, "fingerprint"); ok { if fpValue, ok := searchKey(realitySettings, "fingerprint"); ok {
@ -639,12 +639,12 @@ func (s *SubService) genTrojanLink(inbound *model.Inbound, email string) string
params["security"] = "none" params["security"] = "none"
} }
externalProxies, _ := stream["externalProxy"].([]interface{}) externalProxies, _ := stream["externalProxy"].([]any)
if len(externalProxies) > 0 { if len(externalProxies) > 0 {
links := "" links := ""
for index, externalProxy := range externalProxies { for index, externalProxy := range externalProxies {
ep, _ := externalProxy.(map[string]interface{}) ep, _ := externalProxy.(map[string]any)
newSecurity, _ := ep["forceTls"].(string) newSecurity, _ := ep["forceTls"].(string)
dest, _ := ep["dest"].(string) dest, _ := ep["dest"].(string)
port := int(ep["port"].(float64)) port := int(ep["port"].(float64))
@ -698,11 +698,11 @@ func (s *SubService) genShadowsocksLink(inbound *model.Inbound, email string) st
if inbound.Protocol != model.Shadowsocks { if inbound.Protocol != model.Shadowsocks {
return "" return ""
} }
var stream map[string]interface{} var stream map[string]any
json.Unmarshal([]byte(inbound.StreamSettings), &stream) json.Unmarshal([]byte(inbound.StreamSettings), &stream)
clients, _ := s.inboundService.GetClients(inbound) clients, _ := s.inboundService.GetClients(inbound)
var settings map[string]interface{} var settings map[string]any
json.Unmarshal([]byte(inbound.Settings), &settings) json.Unmarshal([]byte(inbound.Settings), &settings)
inboundPassword := settings["password"].(string) inboundPassword := settings["password"].(string)
method := settings["method"].(string) method := settings["method"].(string)
@ -719,54 +719,54 @@ func (s *SubService) genShadowsocksLink(inbound *model.Inbound, email string) st
switch streamNetwork { switch streamNetwork {
case "tcp": case "tcp":
tcp, _ := stream["tcpSettings"].(map[string]interface{}) tcp, _ := stream["tcpSettings"].(map[string]any)
header, _ := tcp["header"].(map[string]interface{}) header, _ := tcp["header"].(map[string]any)
typeStr, _ := header["type"].(string) typeStr, _ := header["type"].(string)
if typeStr == "http" { if typeStr == "http" {
request := header["request"].(map[string]interface{}) request := header["request"].(map[string]any)
requestPath, _ := request["path"].([]interface{}) requestPath, _ := request["path"].([]any)
params["path"] = requestPath[0].(string) params["path"] = requestPath[0].(string)
headers, _ := request["headers"].(map[string]interface{}) headers, _ := request["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
params["headerType"] = "http" params["headerType"] = "http"
} }
case "kcp": case "kcp":
kcp, _ := stream["kcpSettings"].(map[string]interface{}) kcp, _ := stream["kcpSettings"].(map[string]any)
header, _ := kcp["header"].(map[string]interface{}) header, _ := kcp["header"].(map[string]any)
params["headerType"] = header["type"].(string) params["headerType"] = header["type"].(string)
params["seed"] = kcp["seed"].(string) params["seed"] = kcp["seed"].(string)
case "ws": case "ws":
ws, _ := stream["wsSettings"].(map[string]interface{}) ws, _ := stream["wsSettings"].(map[string]any)
params["path"] = ws["path"].(string) params["path"] = ws["path"].(string)
if host, ok := ws["host"].(string); ok && len(host) > 0 { if host, ok := ws["host"].(string); ok && len(host) > 0 {
params["host"] = host params["host"] = host
} else { } else {
headers, _ := ws["headers"].(map[string]interface{}) headers, _ := ws["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
} }
case "grpc": case "grpc":
grpc, _ := stream["grpcSettings"].(map[string]interface{}) grpc, _ := stream["grpcSettings"].(map[string]any)
params["serviceName"] = grpc["serviceName"].(string) params["serviceName"] = grpc["serviceName"].(string)
params["authority"], _ = grpc["authority"].(string) params["authority"], _ = grpc["authority"].(string)
if grpc["multiMode"].(bool) { if grpc["multiMode"].(bool) {
params["mode"] = "multi" params["mode"] = "multi"
} }
case "httpupgrade": case "httpupgrade":
httpupgrade, _ := stream["httpupgradeSettings"].(map[string]interface{}) httpupgrade, _ := stream["httpupgradeSettings"].(map[string]any)
params["path"] = httpupgrade["path"].(string) params["path"] = httpupgrade["path"].(string)
if host, ok := httpupgrade["host"].(string); ok && len(host) > 0 { if host, ok := httpupgrade["host"].(string); ok && len(host) > 0 {
params["host"] = host params["host"] = host
} else { } else {
headers, _ := httpupgrade["headers"].(map[string]interface{}) headers, _ := httpupgrade["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
} }
case "xhttp": case "xhttp":
xhttp, _ := stream["xhttpSettings"].(map[string]interface{}) xhttp, _ := stream["xhttpSettings"].(map[string]any)
params["path"] = xhttp["path"].(string) params["path"] = xhttp["path"].(string)
if host, ok := xhttp["host"].(string); ok && len(host) > 0 { if host, ok := xhttp["host"].(string); ok && len(host) > 0 {
params["host"] = host params["host"] = host
} else { } else {
headers, _ := xhttp["headers"].(map[string]interface{}) headers, _ := xhttp["headers"].(map[string]any)
params["host"] = searchHost(headers) params["host"] = searchHost(headers)
} }
params["mode"] = xhttp["mode"].(string) params["mode"] = xhttp["mode"].(string)
@ -775,8 +775,8 @@ func (s *SubService) genShadowsocksLink(inbound *model.Inbound, email string) st
security, _ := stream["security"].(string) security, _ := stream["security"].(string)
if security == "tls" { if security == "tls" {
params["security"] = "tls" params["security"] = "tls"
tlsSetting, _ := stream["tlsSettings"].(map[string]interface{}) tlsSetting, _ := stream["tlsSettings"].(map[string]any)
alpns, _ := tlsSetting["alpn"].([]interface{}) alpns, _ := tlsSetting["alpn"].([]any)
var alpn []string var alpn []string
for _, a := range alpns { for _, a := range alpns {
alpn = append(alpn, a.(string)) alpn = append(alpn, a.(string))
@ -806,12 +806,12 @@ func (s *SubService) genShadowsocksLink(inbound *model.Inbound, email string) st
encPart = fmt.Sprintf("%s:%s:%s", method, inboundPassword, clients[clientIndex].Password) encPart = fmt.Sprintf("%s:%s:%s", method, inboundPassword, clients[clientIndex].Password)
} }
externalProxies, _ := stream["externalProxy"].([]interface{}) externalProxies, _ := stream["externalProxy"].([]any)
if len(externalProxies) > 0 { if len(externalProxies) > 0 {
links := "" links := ""
for index, externalProxy := range externalProxies { for index, externalProxy := range externalProxies {
ep, _ := externalProxy.(map[string]interface{}) ep, _ := externalProxy.(map[string]any)
newSecurity, _ := ep["forceTls"].(string) newSecurity, _ := ep["forceTls"].(string)
dest, _ := ep["dest"].(string) dest, _ := ep["dest"].(string)
port := int(ep["port"].(float64)) port := int(ep["port"].(float64))
@ -944,9 +944,9 @@ func (s *SubService) genRemark(inbound *model.Inbound, email string, extra strin
return strings.Join(remark, separationChar) return strings.Join(remark, separationChar)
} }
func searchKey(data interface{}, key string) (interface{}, bool) { func searchKey(data any, key string) (any, bool) {
switch val := data.(type) { switch val := data.(type) {
case map[string]interface{}: case map[string]any:
for k, v := range val { for k, v := range val {
if k == key { if k == key {
return v, true return v, true
@ -955,7 +955,7 @@ func searchKey(data interface{}, key string) (interface{}, bool) {
return result, true return result, true
} }
} }
case []interface{}: case []any:
for _, v := range val { for _, v := range val {
if result, ok := searchKey(v, key); ok { if result, ok := searchKey(v, key); ok {
return result, true return result, true
@ -965,19 +965,19 @@ func searchKey(data interface{}, key string) (interface{}, bool) {
return nil, false return nil, false
} }
func searchHost(headers interface{}) string { func searchHost(headers any) string {
data, _ := headers.(map[string]interface{}) data, _ := headers.(map[string]any)
for k, v := range data { for k, v := range data {
if strings.EqualFold(k, "host") { if strings.EqualFold(k, "host") {
switch v.(type) { switch v.(type) {
case []interface{}: case []any:
hosts, _ := v.([]interface{}) hosts, _ := v.([]any)
if len(hosts) > 0 { if len(hosts) > 0 {
return hosts[0].(string) return hosts[0].(string)
} else { } else {
return "" return ""
} }
case interface{}: case any:
return v.(string) return v.(string)
} }
} }

View file

@ -7,17 +7,17 @@ import (
"x-ui/logger" "x-ui/logger"
) )
func NewErrorf(format string, a ...interface{}) error { func NewErrorf(format string, a ...any) error {
msg := fmt.Sprintf(format, a...) msg := fmt.Sprintf(format, a...)
return errors.New(msg) return errors.New(msg)
} }
func NewError(a ...interface{}) error { func NewError(a ...any) error {
msg := fmt.Sprintln(a...) msg := fmt.Sprintln(a...)
return errors.New(msg) return errors.New(msg)
} }
func Recover(msg string) interface{} { func Recover(msg string) any {
panicErr := recover() panicErr := recover()
if panicErr != nil { if panicErr != nil {
if msg != "" { if msg != "" {

View file

@ -31,11 +31,11 @@ func jsonMsg(c *gin.Context, msg string, err error) {
jsonMsgObj(c, msg, nil, err) jsonMsgObj(c, msg, nil, err)
} }
func jsonObj(c *gin.Context, obj interface{}, err error) { func jsonObj(c *gin.Context, obj any, err error) {
jsonMsgObj(c, "", obj, err) jsonMsgObj(c, "", obj, err)
} }
func jsonMsgObj(c *gin.Context, msg string, obj interface{}, err error) { func jsonMsgObj(c *gin.Context, msg string, obj any, err error) {
m := entity.Msg{ m := entity.Msg{
Obj: obj, Obj: obj,
} }

View file

@ -10,9 +10,9 @@ import (
) )
type Msg struct { type Msg struct {
Success bool `json:"success"` Success bool `json:"success"`
Msg string `json:"msg"` Msg string `json:"msg"`
Obj interface{} `json:"obj"` Obj any `json:"obj"`
} }
type AllSetting struct { type AllSetting struct {

View file

@ -11,6 +11,7 @@ import (
"sort" "sort"
"time" "time"
"slices"
"x-ui/database" "x-ui/database"
"x-ui/database/model" "x-ui/database/model"
"x-ui/logger" "x-ui/logger"
@ -193,13 +194,7 @@ func (j *CheckClientIpJob) checkError(e error) {
} }
func (j *CheckClientIpJob) contains(s []string, str string) bool { func (j *CheckClientIpJob) contains(s []string, str string) bool {
for _, v := range s { return slices.Contains(s, str)
if v == str {
return true
}
}
return false
} }
func (j *CheckClientIpJob) getInboundClientIps(clientEmail string) (*model.InboundClientIps, error) { func (j *CheckClientIpJob) getInboundClientIps(clientEmail string) (*model.InboundClientIps, error) {

View file

@ -52,7 +52,7 @@ func (j *XrayTrafficJob) informTrafficToExternalAPI(inboundTraffics []*xray.Traf
logger.Warning("get ExternalTrafficInformURI failed:", err) logger.Warning("get ExternalTrafficInformURI failed:", err)
return return
} }
requestBody, err := json.Marshal(map[string]interface{}{"clientTraffics": clientTraffics, "inboundTraffics": inboundTraffics}) requestBody, err := json.Marshal(map[string]any{"clientTraffics": clientTraffics, "inboundTraffics": inboundTraffics})
if err != nil { if err != nil {
logger.Warning("parse client/inbound traffic failed:", err) logger.Warning("parse client/inbound traffic failed:", err)
return return

View file

@ -48,13 +48,13 @@ func InitLocalizer(i18nFS embed.FS, settingService SettingService) error {
return nil return nil
} }
func createTemplateData(params []string, seperator ...string) map[string]interface{} { func createTemplateData(params []string, seperator ...string) map[string]any {
var sep string = "==" var sep string = "=="
if len(seperator) > 0 { if len(seperator) > 0 {
sep = seperator[0] sep = seperator[0]
} }
templateData := make(map[string]interface{}) templateData := make(map[string]any)
for _, param := range params { for _, param := range params {
parts := strings.SplitN(param, sep, 2) parts := strings.SplitN(param, sep, 2)
templateData[parts[0]] = parts[1] templateData[parts[0]] = parts[1]

View file

@ -413,13 +413,13 @@ func (s *InboundService) AddInboundClient(data *model.Inbound) (bool, error) {
return false, err return false, err
} }
var settings map[string]interface{} var settings map[string]any
err = json.Unmarshal([]byte(data.Settings), &settings) err = json.Unmarshal([]byte(data.Settings), &settings)
if err != nil { if err != nil {
return false, err return false, err
} }
interfaceClients := settings["clients"].([]interface{}) interfaceClients := settings["clients"].([]any)
existEmail, err := s.checkEmailsExistForClients(clients) existEmail, err := s.checkEmailsExistForClients(clients)
if err != nil { if err != nil {
return false, err return false, err
@ -450,13 +450,13 @@ func (s *InboundService) AddInboundClient(data *model.Inbound) (bool, error) {
} }
} }
var oldSettings map[string]interface{} var oldSettings map[string]any
err = json.Unmarshal([]byte(oldInbound.Settings), &oldSettings) err = json.Unmarshal([]byte(oldInbound.Settings), &oldSettings)
if err != nil { if err != nil {
return false, err return false, err
} }
oldClients := oldSettings["clients"].([]interface{}) oldClients := oldSettings["clients"].([]any)
oldClients = append(oldClients, interfaceClients...) oldClients = append(oldClients, interfaceClients...)
oldSettings["clients"] = oldClients oldSettings["clients"] = oldClients
@ -489,7 +489,7 @@ func (s *InboundService) AddInboundClient(data *model.Inbound) (bool, error) {
if oldInbound.Protocol == "shadowsocks" { if oldInbound.Protocol == "shadowsocks" {
cipher = oldSettings["method"].(string) cipher = oldSettings["method"].(string)
} }
err1 := s.xrayApi.AddUser(string(oldInbound.Protocol), oldInbound.Tag, map[string]interface{}{ err1 := s.xrayApi.AddUser(string(oldInbound.Protocol), oldInbound.Tag, map[string]any{
"email": client.Email, "email": client.Email,
"id": client.ID, "id": client.ID,
"security": client.Security, "security": client.Security,
@ -519,7 +519,7 @@ func (s *InboundService) DelInboundClient(inboundId int, clientId string) (bool,
logger.Error("Load Old Data Error") logger.Error("Load Old Data Error")
return false, err return false, err
} }
var settings map[string]interface{} var settings map[string]any
err = json.Unmarshal([]byte(oldInbound.Settings), &settings) err = json.Unmarshal([]byte(oldInbound.Settings), &settings)
if err != nil { if err != nil {
return false, err return false, err
@ -534,11 +534,11 @@ func (s *InboundService) DelInboundClient(inboundId int, clientId string) (bool,
client_key = "email" client_key = "email"
} }
interfaceClients := settings["clients"].([]interface{}) interfaceClients := settings["clients"].([]any)
var newClients []interface{} var newClients []any
needApiDel := false needApiDel := false
for _, client := range interfaceClients { for _, client := range interfaceClients {
c := client.(map[string]interface{}) c := client.(map[string]any)
c_id := c[client_key].(string) c_id := c[client_key].(string)
if c_id == clientId { if c_id == clientId {
email, _ = c["email"].(string) email, _ = c["email"].(string)
@ -607,13 +607,13 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId strin
return false, err return false, err
} }
var settings map[string]interface{} var settings map[string]any
err = json.Unmarshal([]byte(data.Settings), &settings) err = json.Unmarshal([]byte(data.Settings), &settings)
if err != nil { if err != nil {
return false, err return false, err
} }
interfaceClients := settings["clients"].([]interface{}) interfaceClients := settings["clients"].([]any)
oldInbound, err := s.GetInbound(data.Id) oldInbound, err := s.GetInbound(data.Id)
if err != nil { if err != nil {
@ -662,12 +662,12 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId strin
} }
} }
var oldSettings map[string]interface{} var oldSettings map[string]any
err = json.Unmarshal([]byte(oldInbound.Settings), &oldSettings) err = json.Unmarshal([]byte(oldInbound.Settings), &oldSettings)
if err != nil { if err != nil {
return false, err return false, err
} }
settingsClients := oldSettings["clients"].([]interface{}) settingsClients := oldSettings["clients"].([]any)
settingsClients[clientIndex] = interfaceClients[0] settingsClients[clientIndex] = interfaceClients[0]
oldSettings["clients"] = settingsClients oldSettings["clients"] = settingsClients
@ -732,7 +732,7 @@ func (s *InboundService) UpdateInboundClient(data *model.Inbound, clientId strin
if oldInbound.Protocol == "shadowsocks" { if oldInbound.Protocol == "shadowsocks" {
cipher = oldSettings["method"].(string) cipher = oldSettings["method"].(string)
} }
err1 := s.xrayApi.AddUser(string(oldInbound.Protocol), oldInbound.Tag, map[string]interface{}{ err1 := s.xrayApi.AddUser(string(oldInbound.Protocol), oldInbound.Tag, map[string]any{
"email": clients[0].Email, "email": clients[0].Email,
"id": clients[0].ID, "id": clients[0].ID,
"security": clients[0].Security, "security": clients[0].Security,
@ -809,7 +809,7 @@ func (s *InboundService) addInboundTraffic(tx *gorm.DB, traffics []*xray.Traffic
for _, traffic := range traffics { for _, traffic := range traffics {
if traffic.IsInbound { if traffic.IsInbound {
err = tx.Model(&model.Inbound{}).Where("tag = ?", traffic.Tag). err = tx.Model(&model.Inbound{}).Where("tag = ?", traffic.Tag).
Updates(map[string]interface{}{ Updates(map[string]any{
"up": gorm.Expr("up + ?", traffic.Up), "up": gorm.Expr("up + ?", traffic.Up),
"down": gorm.Expr("down + ?", traffic.Down), "down": gorm.Expr("down + ?", traffic.Down),
}).Error }).Error
@ -893,13 +893,13 @@ func (s *InboundService) adjustTraffics(tx *gorm.DB, dbClientTraffics []*xray.Cl
return nil, err return nil, err
} }
for inbound_index := range inbounds { for inbound_index := range inbounds {
settings := map[string]interface{}{} settings := map[string]any{}
json.Unmarshal([]byte(inbounds[inbound_index].Settings), &settings) json.Unmarshal([]byte(inbounds[inbound_index].Settings), &settings)
clients, ok := settings["clients"].([]interface{}) clients, ok := settings["clients"].([]any)
if ok { if ok {
var newClients []interface{} var newClients []any
for client_index := range clients { for client_index := range clients {
c := clients[client_index].(map[string]interface{}) c := clients[client_index].(map[string]any)
for traffic_index := range dbClientTraffics { for traffic_index := range dbClientTraffics {
if dbClientTraffics[traffic_index].ExpiryTime < 0 && c["email"] == dbClientTraffics[traffic_index].Email { if dbClientTraffics[traffic_index].ExpiryTime < 0 && c["email"] == dbClientTraffics[traffic_index].Email {
oldExpiryTime := c["expiryTime"].(float64) oldExpiryTime := c["expiryTime"].(float64)
@ -909,7 +909,7 @@ func (s *InboundService) adjustTraffics(tx *gorm.DB, dbClientTraffics []*xray.Cl
break break
} }
} }
newClients = append(newClients, interface{}(c)) newClients = append(newClients, any(c))
} }
settings["clients"] = newClients settings["clients"] = newClients
modifiedSettings, err := json.MarshalIndent(settings, "", " ") modifiedSettings, err := json.MarshalIndent(settings, "", " ")
@ -951,7 +951,7 @@ func (s *InboundService) autoRenewClients(tx *gorm.DB) (bool, int64, error) {
var clientsToAdd []struct { var clientsToAdd []struct {
protocol string protocol string
tag string tag string
client map[string]interface{} client map[string]any
} }
for _, traffic := range traffics { for _, traffic := range traffics {
@ -962,11 +962,11 @@ func (s *InboundService) autoRenewClients(tx *gorm.DB) (bool, int64, error) {
return false, 0, err return false, 0, err
} }
for inbound_index := range inbounds { for inbound_index := range inbounds {
settings := map[string]interface{}{} settings := map[string]any{}
json.Unmarshal([]byte(inbounds[inbound_index].Settings), &settings) json.Unmarshal([]byte(inbounds[inbound_index].Settings), &settings)
clients := settings["clients"].([]interface{}) clients := settings["clients"].([]any)
for client_index := range clients { for client_index := range clients {
c := clients[client_index].(map[string]interface{}) c := clients[client_index].(map[string]any)
for traffic_index, traffic := range traffics { for traffic_index, traffic := range traffics {
if traffic.Email == c["email"].(string) { if traffic.Email == c["email"].(string) {
newExpiryTime := traffic.ExpiryTime newExpiryTime := traffic.ExpiryTime
@ -983,14 +983,14 @@ func (s *InboundService) autoRenewClients(tx *gorm.DB) (bool, int64, error) {
struct { struct {
protocol string protocol string
tag string tag string
client map[string]interface{} client map[string]any
}{ }{
protocol: string(inbounds[inbound_index].Protocol), protocol: string(inbounds[inbound_index].Protocol),
tag: inbounds[inbound_index].Tag, tag: inbounds[inbound_index].Tag,
client: c, client: c,
}) })
} }
clients[client_index] = interface{}(c) clients[client_index] = any(c)
break break
} }
} }
@ -1147,7 +1147,7 @@ func (s *InboundService) AddClientStat(tx *gorm.DB, inboundId int, client *model
func (s *InboundService) UpdateClientStat(tx *gorm.DB, email string, client *model.Client) error { func (s *InboundService) UpdateClientStat(tx *gorm.DB, email string, client *model.Client) error {
result := tx.Model(xray.ClientTraffic{}). result := tx.Model(xray.ClientTraffic{}).
Where("email = ?", email). Where("email = ?", email).
Updates(map[string]interface{}{ Updates(map[string]any{
"enable": true, "enable": true,
"email": client.Email, "email": client.Email,
"total": client.TotalGB, "total": client.TotalGB,
@ -1258,18 +1258,18 @@ func (s *InboundService) SetClientTelegramUserID(trafficId int, tgId int64) (boo
return false, common.NewError("Client Not Found For Email:", clientEmail) return false, common.NewError("Client Not Found For Email:", clientEmail)
} }
var settings map[string]interface{} var settings map[string]any
err = json.Unmarshal([]byte(inbound.Settings), &settings) err = json.Unmarshal([]byte(inbound.Settings), &settings)
if err != nil { if err != nil {
return false, err return false, err
} }
clients := settings["clients"].([]interface{}) clients := settings["clients"].([]any)
var newClients []interface{} var newClients []any
for client_index := range clients { for client_index := range clients {
c := clients[client_index].(map[string]interface{}) c := clients[client_index].(map[string]any)
if c["email"] == clientEmail { if c["email"] == clientEmail {
c["tgId"] = tgId c["tgId"] = tgId
newClients = append(newClients, interface{}(c)) newClients = append(newClients, any(c))
} }
} }
settings["clients"] = newClients settings["clients"] = newClients
@ -1343,18 +1343,18 @@ func (s *InboundService) ToggleClientEnableByEmail(clientEmail string) (bool, bo
return false, false, common.NewError("Client Not Found For Email:", clientEmail) return false, false, common.NewError("Client Not Found For Email:", clientEmail)
} }
var settings map[string]interface{} var settings map[string]any
err = json.Unmarshal([]byte(inbound.Settings), &settings) err = json.Unmarshal([]byte(inbound.Settings), &settings)
if err != nil { if err != nil {
return false, false, err return false, false, err
} }
clients := settings["clients"].([]interface{}) clients := settings["clients"].([]any)
var newClients []interface{} var newClients []any
for client_index := range clients { for client_index := range clients {
c := clients[client_index].(map[string]interface{}) c := clients[client_index].(map[string]any)
if c["email"] == clientEmail { if c["email"] == clientEmail {
c["enable"] = !clientOldEnabled c["enable"] = !clientOldEnabled
newClients = append(newClients, interface{}(c)) newClients = append(newClients, any(c))
} }
} }
settings["clients"] = newClients settings["clients"] = newClients
@ -1405,18 +1405,18 @@ func (s *InboundService) ResetClientIpLimitByEmail(clientEmail string, count int
return false, common.NewError("Client Not Found For Email:", clientEmail) return false, common.NewError("Client Not Found For Email:", clientEmail)
} }
var settings map[string]interface{} var settings map[string]any
err = json.Unmarshal([]byte(inbound.Settings), &settings) err = json.Unmarshal([]byte(inbound.Settings), &settings)
if err != nil { if err != nil {
return false, err return false, err
} }
clients := settings["clients"].([]interface{}) clients := settings["clients"].([]any)
var newClients []interface{} var newClients []any
for client_index := range clients { for client_index := range clients {
c := clients[client_index].(map[string]interface{}) c := clients[client_index].(map[string]any)
if c["email"] == clientEmail { if c["email"] == clientEmail {
c["limitIp"] = count c["limitIp"] = count
newClients = append(newClients, interface{}(c)) newClients = append(newClients, any(c))
} }
} }
settings["clients"] = newClients settings["clients"] = newClients
@ -1462,18 +1462,18 @@ func (s *InboundService) ResetClientExpiryTimeByEmail(clientEmail string, expiry
return false, common.NewError("Client Not Found For Email:", clientEmail) return false, common.NewError("Client Not Found For Email:", clientEmail)
} }
var settings map[string]interface{} var settings map[string]any
err = json.Unmarshal([]byte(inbound.Settings), &settings) err = json.Unmarshal([]byte(inbound.Settings), &settings)
if err != nil { if err != nil {
return false, err return false, err
} }
clients := settings["clients"].([]interface{}) clients := settings["clients"].([]any)
var newClients []interface{} var newClients []any
for client_index := range clients { for client_index := range clients {
c := clients[client_index].(map[string]interface{}) c := clients[client_index].(map[string]any)
if c["email"] == clientEmail { if c["email"] == clientEmail {
c["expiryTime"] = expiry_time c["expiryTime"] = expiry_time
newClients = append(newClients, interface{}(c)) newClients = append(newClients, any(c))
} }
} }
settings["clients"] = newClients settings["clients"] = newClients
@ -1522,18 +1522,18 @@ func (s *InboundService) ResetClientTrafficLimitByEmail(clientEmail string, tota
return false, common.NewError("Client Not Found For Email:", clientEmail) return false, common.NewError("Client Not Found For Email:", clientEmail)
} }
var settings map[string]interface{} var settings map[string]any
err = json.Unmarshal([]byte(inbound.Settings), &settings) err = json.Unmarshal([]byte(inbound.Settings), &settings)
if err != nil { if err != nil {
return false, err return false, err
} }
clients := settings["clients"].([]interface{}) clients := settings["clients"].([]any)
var newClients []interface{} var newClients []any
for client_index := range clients { for client_index := range clients {
c := clients[client_index].(map[string]interface{}) c := clients[client_index].(map[string]any)
if c["email"] == clientEmail { if c["email"] == clientEmail {
c["totalGB"] = totalGB * 1024 * 1024 * 1024 c["totalGB"] = totalGB * 1024 * 1024 * 1024
newClients = append(newClients, interface{}(c)) newClients = append(newClients, any(c))
} }
} }
settings["clients"] = newClients settings["clients"] = newClients
@ -1551,7 +1551,7 @@ func (s *InboundService) ResetClientTrafficByEmail(clientEmail string) error {
result := db.Model(xray.ClientTraffic{}). result := db.Model(xray.ClientTraffic{}).
Where("email = ?", clientEmail). Where("email = ?", clientEmail).
Updates(map[string]interface{}{"enable": true, "up": 0, "down": 0}) Updates(map[string]any{"enable": true, "up": 0, "down": 0})
err := result.Error err := result.Error
if err != nil { if err != nil {
@ -1582,14 +1582,14 @@ func (s *InboundService) ResetClientTraffic(id int, clientEmail string) (bool, e
s.xrayApi.Init(p.GetAPIPort()) s.xrayApi.Init(p.GetAPIPort())
cipher := "" cipher := ""
if string(inbound.Protocol) == "shadowsocks" { if string(inbound.Protocol) == "shadowsocks" {
var oldSettings map[string]interface{} var oldSettings map[string]any
err = json.Unmarshal([]byte(inbound.Settings), &oldSettings) err = json.Unmarshal([]byte(inbound.Settings), &oldSettings)
if err != nil { if err != nil {
return false, err return false, err
} }
cipher = oldSettings["method"].(string) cipher = oldSettings["method"].(string)
} }
err1 := s.xrayApi.AddUser(string(inbound.Protocol), inbound.Tag, map[string]interface{}{ err1 := s.xrayApi.AddUser(string(inbound.Protocol), inbound.Tag, map[string]any{
"email": client.Email, "email": client.Email,
"id": client.ID, "id": client.ID,
"security": client.Security, "security": client.Security,
@ -1634,7 +1634,7 @@ func (s *InboundService) ResetAllClientTraffics(id int) error {
result := db.Model(xray.ClientTraffic{}). result := db.Model(xray.ClientTraffic{}).
Where(whereText, id). Where(whereText, id).
Updates(map[string]interface{}{"enable": true, "up": 0, "down": 0}) Updates(map[string]any{"enable": true, "up": 0, "down": 0})
err := result.Error err := result.Error
return err return err
@ -1645,7 +1645,7 @@ func (s *InboundService) ResetAllTraffics() error {
result := db.Model(model.Inbound{}). result := db.Model(model.Inbound{}).
Where("user_id > ?", 0). Where("user_id > ?", 0).
Updates(map[string]interface{}{"up": 0, "down": 0}) Updates(map[string]any{"up": 0, "down": 0})
err := result.Error err := result.Error
return err return err
@ -1681,17 +1681,17 @@ func (s *InboundService) DelDepletedClients(id int) (err error) {
if err != nil { if err != nil {
return err return err
} }
var oldSettings map[string]interface{} var oldSettings map[string]any
err = json.Unmarshal([]byte(oldInbound.Settings), &oldSettings) err = json.Unmarshal([]byte(oldInbound.Settings), &oldSettings)
if err != nil { if err != nil {
return err return err
} }
oldClients := oldSettings["clients"].([]interface{}) oldClients := oldSettings["clients"].([]any)
var newClients []interface{} var newClients []any
for _, client := range oldClients { for _, client := range oldClients {
deplete := false deplete := false
c := client.(map[string]interface{}) c := client.(map[string]any)
for _, email := range emails { for _, email := range emails {
if email == c["email"].(string) { if email == c["email"].(string) {
deplete = true deplete = true
@ -1907,14 +1907,14 @@ func (s *InboundService) MigrationRequirements() {
return return
} }
for inbound_index := range inbounds { for inbound_index := range inbounds {
settings := map[string]interface{}{} settings := map[string]any{}
json.Unmarshal([]byte(inbounds[inbound_index].Settings), &settings) json.Unmarshal([]byte(inbounds[inbound_index].Settings), &settings)
clients, ok := settings["clients"].([]interface{}) clients, ok := settings["clients"].([]any)
if ok { if ok {
// Fix Client configuration problems // Fix Client configuration problems
var newClients []interface{} var newClients []any
for client_index := range clients { for client_index := range clients {
c := clients[client_index].(map[string]interface{}) c := clients[client_index].(map[string]any)
// Add email='' if it is not exists // Add email='' if it is not exists
if _, ok := c["email"]; !ok { if _, ok := c["email"]; !ok {
@ -1923,7 +1923,7 @@ func (s *InboundService) MigrationRequirements() {
// Convert string tgId to int64 // Convert string tgId to int64
if _, ok := c["tgId"]; ok { if _, ok := c["tgId"]; ok {
var tgId interface{} = c["tgId"] var tgId any = c["tgId"]
if tgIdStr, ok2 := tgId.(string); ok2 { if tgIdStr, ok2 := tgId.(string); ok2 {
tgIdInt64, err := strconv.ParseInt(strings.ReplaceAll(tgIdStr, " ", ""), 10, 64) tgIdInt64, err := strconv.ParseInt(strings.ReplaceAll(tgIdStr, " ", ""), 10, 64)
if err == nil { if err == nil {
@ -1938,7 +1938,7 @@ func (s *InboundService) MigrationRequirements() {
c["flow"] = "" c["flow"] = ""
} }
} }
newClients = append(newClients, interface{}(c)) newClients = append(newClients, any(c))
} }
settings["clients"] = newClients settings["clients"] = newClients
modifiedSettings, err := json.MarshalIndent(settings, "", " ") modifiedSettings, err := json.MarshalIndent(settings, "", " ")
@ -1985,14 +1985,14 @@ func (s *InboundService) MigrationRequirements() {
} }
for _, ep := range externalProxy { for _, ep := range externalProxy {
var reverses interface{} var reverses any
var stream map[string]interface{} var stream map[string]any
json.Unmarshal(ep.StreamSettings, &stream) json.Unmarshal(ep.StreamSettings, &stream)
if tlsSettings, ok := stream["tlsSettings"].(map[string]interface{}); ok { if tlsSettings, ok := stream["tlsSettings"].(map[string]any); ok {
if settings, ok := tlsSettings["settings"].(map[string]interface{}); ok { if settings, ok := tlsSettings["settings"].(map[string]any); ok {
if domains, ok := settings["domains"].([]interface{}); ok { if domains, ok := settings["domains"].([]any); ok {
for _, domain := range domains { for _, domain := range domains {
if domainMap, ok := domain.(map[string]interface{}); ok { if domainMap, ok := domain.(map[string]any); ok {
domainMap["forceTls"] = "same" domainMap["forceTls"] = "same"
domainMap["port"] = ep.Port domainMap["port"] = ep.Port
domainMap["dest"] = domainMap["domain"].(string) domainMap["dest"] = domainMap["domain"].(string)

View file

@ -89,7 +89,7 @@ func (s *OutboundService) ResetOutboundTraffic(tag string) error {
result := db.Model(model.OutboundTraffics{}). result := db.Model(model.OutboundTraffics{}).
Where(whereText, tag). Where(whereText, tag).
Updates(map[string]interface{}{"up": 0, "down": 0, "total": 0}) Updates(map[string]any{"up": 0, "down": 0, "total": 0})
err := result.Error err := result.Error
if err != nil { if err != nil {

View file

@ -450,7 +450,7 @@ func (s *ServerService) GetLogs(count string, level string, syslog string) []str
return lines return lines
} }
func (s *ServerService) GetConfigJson() (interface{}, error) { func (s *ServerService) GetConfigJson() (any, error) {
config, err := s.xrayService.GetXrayConfig() config, err := s.xrayService.GetXrayConfig()
if err != nil { if err != nil {
return nil, err return nil, err
@ -460,7 +460,7 @@ func (s *ServerService) GetConfigJson() (interface{}, error) {
return nil, err return nil, err
} }
var jsonData interface{} var jsonData any
err = json.Unmarshal(contents, &jsonData) err = json.Unmarshal(contents, &jsonData)
if err != nil { if err != nil {
return nil, err return nil, err
@ -591,7 +591,7 @@ func (s *ServerService) ImportDB(file multipart.File) error {
return nil return nil
} }
func (s *ServerService) GetNewX25519Cert() (interface{}, error) { func (s *ServerService) GetNewX25519Cert() (any, error) {
// Run the command // Run the command
cmd := exec.Command(xray.GetBinaryPath(), "x25519") cmd := exec.Command(xray.GetBinaryPath(), "x25519")
var out bytes.Buffer var out bytes.Buffer
@ -609,7 +609,7 @@ func (s *ServerService) GetNewX25519Cert() (interface{}, error) {
privateKey := strings.TrimSpace(privateKeyLine[1]) privateKey := strings.TrimSpace(privateKeyLine[1])
publicKey := strings.TrimSpace(publicKeyLine[1]) publicKey := strings.TrimSpace(publicKeyLine[1])
keyPair := map[string]interface{}{ keyPair := map[string]any{
"privateKey": privateKey, "privateKey": privateKey,
"publicKey": publicKey, "publicKey": publicKey,
} }

View file

@ -74,8 +74,8 @@ var defaultValueMap = map[string]string{
type SettingService struct{} type SettingService struct{}
func (s *SettingService) GetDefaultJsonConfig() (interface{}, error) { func (s *SettingService) GetDefaultJsonConfig() (any, error) {
var jsonData interface{} var jsonData any
err := json.Unmarshal([]byte(xrayTemplateConfig), &jsonData) err := json.Unmarshal([]byte(xrayTemplateConfig), &jsonData)
if err != nil { if err != nil {
return nil, err return nil, err
@ -543,8 +543,8 @@ func (s *SettingService) UpdateAllSetting(allSetting *entity.AllSetting) error {
return common.Combine(errs...) return common.Combine(errs...)
} }
func (s *SettingService) GetDefaultXrayConfig() (interface{}, error) { func (s *SettingService) GetDefaultXrayConfig() (any, error) {
var jsonData interface{} var jsonData any
err := json.Unmarshal([]byte(xrayTemplateConfig), &jsonData) err := json.Unmarshal([]byte(xrayTemplateConfig), &jsonData)
if err != nil { if err != nil {
return nil, err return nil, err
@ -552,24 +552,24 @@ func (s *SettingService) GetDefaultXrayConfig() (interface{}, error) {
return jsonData, nil return jsonData, nil
} }
func (s *SettingService) GetDefaultSettings(host string) (interface{}, error) { func (s *SettingService) GetDefaultSettings(host string) (any, error) {
type settingFunc func() (interface{}, error) type settingFunc func() (any, error)
settings := map[string]settingFunc{ settings := map[string]settingFunc{
"expireDiff": func() (interface{}, error) { return s.GetExpireDiff() }, "expireDiff": func() (any, error) { return s.GetExpireDiff() },
"trafficDiff": func() (interface{}, error) { return s.GetTrafficDiff() }, "trafficDiff": func() (any, error) { return s.GetTrafficDiff() },
"pageSize": func() (interface{}, error) { return s.GetPageSize() }, "pageSize": func() (any, error) { return s.GetPageSize() },
"defaultCert": func() (interface{}, error) { return s.GetCertFile() }, "defaultCert": func() (any, error) { return s.GetCertFile() },
"defaultKey": func() (interface{}, error) { return s.GetKeyFile() }, "defaultKey": func() (any, error) { return s.GetKeyFile() },
"tgBotEnable": func() (interface{}, error) { return s.GetTgbotEnabled() }, "tgBotEnable": func() (any, error) { return s.GetTgbotEnabled() },
"subEnable": func() (interface{}, error) { return s.GetSubEnable() }, "subEnable": func() (any, error) { return s.GetSubEnable() },
"subURI": func() (interface{}, error) { return s.GetSubURI() }, "subURI": func() (any, error) { return s.GetSubURI() },
"subJsonURI": func() (interface{}, error) { return s.GetSubJsonURI() }, "subJsonURI": func() (any, error) { return s.GetSubJsonURI() },
"remarkModel": func() (interface{}, error) { return s.GetRemarkModel() }, "remarkModel": func() (any, error) { return s.GetRemarkModel() },
"datepicker": func() (interface{}, error) { return s.GetDatepicker() }, "datepicker": func() (any, error) { return s.GetDatepicker() },
"ipLimitEnable": func() (interface{}, error) { return s.GetIpLimitEnable() }, "ipLimitEnable": func() (any, error) { return s.GetIpLimitEnable() },
} }
result := make(map[string]interface{}) result := make(map[string]any)
for key, fn := range settings { for key, fn := range settings {
value, err := fn() value, err := fn()

View file

@ -20,6 +20,8 @@ import (
"x-ui/web/locale" "x-ui/web/locale"
"x-ui/xray" "x-ui/xray"
"slices"
"github.com/mymmrac/telego" "github.com/mymmrac/telego"
th "github.com/mymmrac/telego/telegohandler" th "github.com/mymmrac/telego/telegohandler"
tu "github.com/mymmrac/telego/telegoutil" tu "github.com/mymmrac/telego/telegoutil"
@ -894,12 +896,7 @@ func (t *Tgbot) answerCallback(callbackQuery *telego.CallbackQuery, isAdmin bool
} }
func checkAdmin(tgId int64) bool { func checkAdmin(tgId int64) bool {
for _, adminId := range adminIds { return slices.Contains(adminIds, tgId)
if adminId == tgId {
return true
}
}
return false
} }
func (t *Tgbot) SendAnswer(chatId int64, msg string, isAdmin bool) { func (t *Tgbot) SendAnswer(chatId int64, msg string, isAdmin bool) {
@ -1692,12 +1689,7 @@ func (t *Tgbot) notifyExhausted() {
} }
func int64Contains(slice []int64, item int64) bool { func int64Contains(slice []int64, item int64) bool {
for _, s := range slice { return slices.Contains(slice, item)
if s == item {
return true
}
}
return false
} }
func (t *Tgbot) onlineClients(chatId int64, messageID ...int) { func (t *Tgbot) onlineClients(chatId int64, messageID ...int) {

View file

@ -46,7 +46,7 @@ func (s *UserService) UpdateUser(id int, username string, password string) error
db := database.GetDB() db := database.GetDB()
return db.Model(model.User{}). return db.Model(model.User{}).
Where("id = ?", id). Where("id = ?", id).
Updates(map[string]interface{}{"username": username, "password": password}). Updates(map[string]any{"username": username, "password": password}).
Error Error
} }

View file

@ -56,7 +56,7 @@ func (s *XrayService) GetXrayVersion() string {
return p.GetVersion() return p.GetVersion()
} }
func RemoveIndex(s []interface{}, index int) []interface{} { func RemoveIndex(s []any, index int) []any {
return append(s[:index], s[index+1:]...) return append(s[:index], s[index+1:]...)
} }
@ -83,16 +83,16 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
continue continue
} }
// get settings clients // get settings clients
settings := map[string]interface{}{} settings := map[string]any{}
json.Unmarshal([]byte(inbound.Settings), &settings) json.Unmarshal([]byte(inbound.Settings), &settings)
clients, ok := settings["clients"].([]interface{}) clients, ok := settings["clients"].([]any)
if ok { if ok {
// check users active or not // check users active or not
clientStats := inbound.ClientStats clientStats := inbound.ClientStats
for _, clientTraffic := range clientStats { for _, clientTraffic := range clientStats {
indexDecrease := 0 indexDecrease := 0
for index, client := range clients { for index, client := range clients {
c := client.(map[string]interface{}) c := client.(map[string]any)
if c["email"] == clientTraffic.Email { if c["email"] == clientTraffic.Email {
if !clientTraffic.Enable { if !clientTraffic.Enable {
clients = RemoveIndex(clients, index-indexDecrease) clients = RemoveIndex(clients, index-indexDecrease)
@ -104,9 +104,9 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
} }
// clear client config for additional parameters // clear client config for additional parameters
var final_clients []interface{} var final_clients []any
for _, client := range clients { for _, client := range clients {
c := client.(map[string]interface{}) c := client.(map[string]any)
if c["enable"] != nil { if c["enable"] != nil {
if enable, ok := c["enable"].(bool); ok && !enable { if enable, ok := c["enable"].(bool); ok && !enable {
continue continue
@ -120,7 +120,7 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
c["flow"] = "xtls-rprx-vision" c["flow"] = "xtls-rprx-vision"
} }
} }
final_clients = append(final_clients, interface{}(c)) final_clients = append(final_clients, any(c))
} }
settings["clients"] = final_clients settings["clients"] = final_clients
@ -134,12 +134,12 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
if len(inbound.StreamSettings) > 0 { if len(inbound.StreamSettings) > 0 {
// Unmarshal stream JSON // Unmarshal stream JSON
var stream map[string]interface{} var stream map[string]any
json.Unmarshal([]byte(inbound.StreamSettings), &stream) json.Unmarshal([]byte(inbound.StreamSettings), &stream)
// Remove the "settings" field under "tlsSettings" and "realitySettings" // Remove the "settings" field under "tlsSettings" and "realitySettings"
tlsSettings, ok1 := stream["tlsSettings"].(map[string]interface{}) tlsSettings, ok1 := stream["tlsSettings"].(map[string]any)
realitySettings, ok2 := stream["realitySettings"].(map[string]interface{}) realitySettings, ok2 := stream["realitySettings"].(map[string]any)
if ok1 || ok2 { if ok1 || ok2 {
if ok1 { if ok1 {
delete(tlsSettings, "settings") delete(tlsSettings, "settings")

View file

@ -92,7 +92,7 @@ func (x *XrayAPI) DelInbound(tag string) error {
return err return err
} }
func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]interface{}) error { func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]any) error {
var account *serial.TypedMessage var account *serial.TypedMessage
switch Protocol { switch Protocol {
case "vmess": case "vmess":

View file

@ -64,7 +64,7 @@ func GetAccessLogPath() (string, error) {
return "", err return "", err
} }
jsonConfig := map[string]interface{}{} jsonConfig := map[string]any{}
err = json.Unmarshal([]byte(config), &jsonConfig) err = json.Unmarshal([]byte(config), &jsonConfig)
if err != nil { if err != nil {
logger.Warningf("Failed to parse JSON configuration: %s", err) logger.Warningf("Failed to parse JSON configuration: %s", err)
@ -72,7 +72,7 @@ func GetAccessLogPath() (string, error) {
} }
if jsonConfig["log"] != nil { if jsonConfig["log"] != nil {
jsonLog := jsonConfig["log"].(map[string]interface{}) jsonLog := jsonConfig["log"].(map[string]any)
if jsonLog["access"] != nil { if jsonLog["access"] != nil {
accessLogPath := jsonLog["access"].(string) accessLogPath := jsonLog["access"].(string)
return accessLogPath, nil return accessLogPath, nil