Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/job/ldap_sync_job.go5
-rw-r--r--web/locale/locale.go2
-rw-r--r--web/service/setting.go8
-rw-r--r--web/service/tgbot.go36
4 files changed, 23 insertions, 28 deletions
diff --git a/web/job/ldap_sync_job.go b/web/job/ldap_sync_job.go
index a947eb73..7edb8178 100644
--- a/web/job/ldap_sync_job.go
+++ b/web/job/ldap_sync_job.go
@@ -271,10 +271,7 @@ func (j *LdapSyncJob) deleteClientsNotInLDAP(inboundTag string, ldapEmails map[s
// Delete in batches
for i := 0; i < len(toDelete); i += batchSize {
- end := i + batchSize
- if end > len(toDelete) {
- end = len(toDelete)
- }
+ end := min(i+batchSize, len(toDelete))
batch := toDelete[i:end]
for _, c := range batch {
diff --git a/web/locale/locale.go b/web/locale/locale.go
index c469911a..73da75b4 100644
--- a/web/locale/locale.go
+++ b/web/locale/locale.go
@@ -37,7 +37,7 @@ type SettingService interface {
// InitLocalizer initializes the internationalization system with embedded translation files.
func InitLocalizer(i18nFS embed.FS, settingService SettingService) error {
- // set default bundle to english
+ // set default bundle to English
i18nBundle = i18n.NewBundle(language.MustParse("en-US"))
i18nBundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
diff --git a/web/service/setting.go b/web/service/setting.go
index 33012c39..5c93e9fd 100644
--- a/web/service/setting.go
+++ b/web/service/setting.go
@@ -108,7 +108,7 @@ var defaultValueMap = map[string]string{
// It handles configuration storage, retrieval, and validation for all system settings.
type SettingService struct{}
-func (s *SettingService) GetDefaultJsonConfig() (any, error) {
+func (s *SettingService) GetDefaultJSONConfig() (any, error) {
var jsonData any
err := json.Unmarshal([]byte(xrayTemplateConfig), &jsonData)
if err != nil {
@@ -125,7 +125,7 @@ func (s *SettingService) GetAllSetting() (*entity.AllSetting, error) {
return nil, err
}
allSetting := &entity.AllSetting{}
- t := reflect.TypeOf(allSetting).Elem()
+ t := reflect.TypeFor[entity.AllSetting]()
v := reflect.ValueOf(allSetting).Elem()
fields := reflect_util.GetFields(t)
@@ -607,7 +607,7 @@ func (s *SettingService) GetIpLimitEnable() (bool, error) {
return (accessLogPath != "none" && accessLogPath != ""), nil
}
-// LDAP exported getters
+// GetLdapEnable returns whether LDAP is enabled.
func (s *SettingService) GetLdapEnable() (bool, error) {
return s.getBool("ldapEnable")
}
@@ -694,7 +694,7 @@ func (s *SettingService) UpdateAllSetting(allSetting *entity.AllSetting) error {
}
v := reflect.ValueOf(allSetting).Elem()
- t := reflect.TypeOf(allSetting).Elem()
+ t := reflect.TypeFor[entity.AllSetting]()
fields := reflect_util.GetFields(t)
errs := make([]error, 0)
for _, field := range fields {
diff --git a/web/service/tgbot.go b/web/service/tgbot.go
index 6bb335b9..6a49f1d3 100644
--- a/web/service/tgbot.go
+++ b/web/service/tgbot.go
@@ -16,6 +16,7 @@ import (
"net/url"
"os"
"regexp"
+ "slices"
"strconv"
"strings"
"sync"
@@ -2719,7 +2720,7 @@ func (t *Tgbot) prepareServerUsageInfo() string {
info += t.I18nBot("tgbot.messages.ip", "IP=="+t.I18nBot("tgbot.unknown"))
info += "\r\n"
} else {
- for i := 0; i < len(netInterfaces); i++ {
+ for i := range netInterfaces {
if (netInterfaces[i].Flags & net.FlagUp) != 0 {
addrs, _ := netInterfaces[i].Addrs()
@@ -2788,29 +2789,29 @@ func (t *Tgbot) UserLoginNotify(username string, password string, ip string, tim
// getInboundUsages retrieves and formats inbound usage information.
func (t *Tgbot) getInboundUsages() string {
- info := ""
+ var info strings.Builder
// get traffic
inbounds, err := t.inboundService.GetAllInbounds()
if err != nil {
logger.Warning("GetAllInbounds run failed:", err)
- info += t.I18nBot("tgbot.answers.getInboundsFailed")
+ info.WriteString(t.I18nBot("tgbot.answers.getInboundsFailed"))
} else {
// NOTE:If there no any sessions here,need to notify here
// TODO:Sub-node push, automatic conversion format
for _, inbound := range inbounds {
- info += t.I18nBot("tgbot.messages.inbound", "Remark=="+inbound.Remark)
- info += t.I18nBot("tgbot.messages.port", "Port=="+strconv.Itoa(inbound.Port))
- info += t.I18nBot("tgbot.messages.traffic", "Total=="+common.FormatTraffic((inbound.Up+inbound.Down)), "Upload=="+common.FormatTraffic(inbound.Up), "Download=="+common.FormatTraffic(inbound.Down))
+ info.WriteString(t.I18nBot("tgbot.messages.inbound", "Remark=="+inbound.Remark))
+ info.WriteString(t.I18nBot("tgbot.messages.port", "Port=="+strconv.Itoa(inbound.Port)))
+ info.WriteString(t.I18nBot("tgbot.messages.traffic", "Total=="+common.FormatTraffic((inbound.Up+inbound.Down)), "Upload=="+common.FormatTraffic(inbound.Up), "Download=="+common.FormatTraffic(inbound.Down)))
if inbound.ExpiryTime == 0 {
- info += t.I18nBot("tgbot.messages.expire", "Time=="+t.I18nBot("tgbot.unlimited"))
+ info.WriteString(t.I18nBot("tgbot.messages.expire", "Time=="+t.I18nBot("tgbot.unlimited")))
} else {
- info += t.I18nBot("tgbot.messages.expire", "Time=="+time.Unix((inbound.ExpiryTime/1000), 0).Format("2006-01-02 15:04:05"))
+ info.WriteString(t.I18nBot("tgbot.messages.expire", "Time=="+time.Unix((inbound.ExpiryTime/1000), 0).Format("2006-01-02 15:04:05")))
}
- info += "\r\n"
+ info.WriteString("\r\n")
}
}
- return info
+ return info.String()
}
// getInbounds creates an inline keyboard with all inbounds.
@@ -3060,12 +3061,9 @@ func (t *Tgbot) clientInfoMsg(
status := t.I18nBot("tgbot.offline")
isOnline := false
if p.IsRunning() {
- for _, online := range p.GetOnlineClients() {
- if online == traffic.Email {
- status = t.I18nBot("tgbot.online")
- isOnline = true
- break
- }
+ if slices.Contains(p.GetOnlineClients(), traffic.Email) {
+ status = t.I18nBot("tgbot.online")
+ isOnline = true
}
}
@@ -3430,11 +3428,11 @@ func (t *Tgbot) searchInbound(chatId int64, remark string) {
t.SendMsgToTgbot(chatId, info)
if len(inbound.ClientStats) > 0 {
- output := ""
+ var output strings.Builder
for _, traffic := range inbound.ClientStats {
- output += t.clientInfoMsg(&traffic, true, true, true, true, true, true)
+ output.WriteString(t.clientInfoMsg(&traffic, true, true, true, true, true, true))
}
- t.SendMsgToTgbot(chatId, output)
+ t.SendMsgToTgbot(chatId, output.String())
}
}
}