Skip to content

Commit 9d27ee0

Browse files
fix: resolve all golangci-lint issues
- Rename strat->strategy throughout (misspell) - Pre-allocate slices in tray.go, pac.go (prealloc) - Fix unchecked Write/Run calls (errcheck) - Remove unused mu field, errSOCKS5* vars (unused) - Fix deprecated filepath.HasPrefix->strings.HasPrefix - Remove impossible nil check in test Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b30fe52 commit 9d27ee0

13 files changed

Lines changed: 78 additions & 35 deletions

File tree

24 KB
Binary file not shown.

‎internal/_trans_data.json‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"LangFR": {
3+
"Возможности YouTube": "Fonctionnalités YouTube",
4+
"TUN режим блокирует весь исходящий трафик кроме Conduit. Включайте только если понимаете риск.": "Le mode TUN bloque tout le trafic sortant sauf Conduit. Activez-le seulement si vous comprenez le risque.",
5+
"Доступна версия %s. Установить сейчас?": "Version %s disponible. Installer maintenant ?",
6+
"Загрузка %d%%": "Téléchargement %d%%",
7+
"Задержка: %dмс, Скачивание: %.1f Мбит/с": "Latence : %dms, Téléchargement : %.1f Mbit/s",
8+
"Локальный прокси Conduit без аутентификации будет использоваться другими приложениями на этом компьютере в пределах allowlist. Включайте только если понимаете риск.": "Le proxy local Conduit sans authentification sera utilisé par d'autres applications sur cet ordinateur dans la limite de l'allowlist. Activez-le seulement si vous comprenez le risque.",
9+
"Соединение OK": "Connexion OK",
10+
"Порты": "Ports",
11+
"работает": "en cours",
12+
"Обновления": "Mises à jour",
13+
"Порт SOCKS5: %d": "Port SOCKS5 : %d",
14+
"Блокировать системный DNS": "Bloquer le DNS système",
15+
"Прокси %s (:%d) | %s | %s DoH | %s": "Proxy %s (:%d) | %s | %s DoH | %s",
16+
"Напомнить позже": "Rappeler plus tard",
17+
"Требуется перезапуск": "Redémarrage requis",
18+
"Заблокировано доменов: %d": "Domaines bloqués : %d",
19+
"Авто-подключение": "Connexion automatique",
20+
"Экспорт настроек": "Exporter les paramètres",
21+
"Импорт настроек": "Importer les paramètres",
22+
"Только YouTube": "YouTube uniquement",
23+
"Выбран %s (%dмс)": "%s sélectionné (%dms)",
24+
"Соединение не удалось: %s": "Connexion échouée : %s",
25+
"Доступно v%s": "Disponible v%s",
26+
"Проверить сейчас": "Vérifier maintenant",
27+
"Настройка портов": "Configurer les ports",
28+
"Стратегия DPI": "Stratégie DPI",
29+
"Сбросить custom": "Réinitialiser custom",
30+
"Системный прокси": "Proxy système",
31+
"Обновление готово": "Mise à jour prête",
32+
"Выйти из PiP": "Quitter le PiP",
33+
"Перезагрузить YouTube": "Recharger YouTube",
34+
"Настройки загружены": "Paramètres importés",
35+
"Загрузка списка...": "Chargement de la liste...",
36+
"Блокировка рекламы (DNS)": "Blocage de pub (DNS)",
37+
"Домены": "Domaines",
38+
"Сброс DNS кэша": "Vider le cache DNS",
39+
"Фоновое аудио": "Audio en arrière-plan",
40+
"Статистика": "Statistiques"
41+
}
42+
}

‎internal/app/settings.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func ApplyPreferences(p Preferences, settings *config.Settings) {
4242
settings.WindowHeight = p.WindowHeight
4343
}
4444

45-
if p.DomainStrategies != nil && len(p.DomainStrategies) > 0 {
45+
if len(p.DomainStrategies) > 0 {
4646
settings.DomainStrategies = make(map[string]string, len(p.DomainStrategies))
4747
for k, v := range p.DomainStrategies {
4848
settings.DomainStrategies[k] = v

‎internal/app/tray.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (ui *trayUI) rebuildMenu() {
126126
ui.statusItem.SetEnabled(false)
127127

128128
// DPI strategies
129-
var strategyItems []*application.MenuItem
129+
strategyItems := make([]*application.MenuItem, 0, len(ui.deps.control.ListStrategies()))
130130
for _, strategy := range ui.deps.control.ListStrategies() {
131131
s := strategy
132132
item := application.NewMenuItemRadio(strategyMenuLabel(lang, s), ui.deps.control.Settings().Strategy == s)
@@ -140,7 +140,7 @@ func (ui *trayUI) rebuildMenu() {
140140
strategyMenu := menuFromItems(strategyItems)
141141

142142
// DNS providers
143-
var dnsItems []*application.MenuItem
143+
dnsItems := make([]*application.MenuItem, 0, len(ui.deps.control.ListDoHProviders()))
144144
for _, provider := range ui.deps.control.ListDoHProviders() {
145145
pr := provider
146146
item := application.NewMenuItemRadio(provider.ShortLabel(), ui.deps.control.Settings().DoHProvider == pr)
@@ -185,7 +185,7 @@ func (ui *trayUI) rebuildMenu() {
185185
dnsMenu := menuFromItems(dnsSubItems)
186186

187187
// Domains
188-
var domainItems []*application.MenuItem
188+
domainItems := make([]*application.MenuItem, 0, len(ui.deps.control.ListAllowlistPresets()))
189189
for _, preset := range ui.deps.control.ListAllowlistPresets() {
190190
pr := preset
191191
label := domainPresetLabel(lang, pr)

‎internal/dns/doh.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func parseDoHResponse(body []byte) ([]net.IP, time.Duration, error) {
238238
return nil, 0, err
239239
}
240240

241-
var ips []net.IP
241+
ips := make([]net.IP, 0, len(payload.Answer))
242242
var minTTL int
243243
for _, answer := range payload.Answer {
244244
if answer.Type != 1 && answer.Type != 28 {

‎internal/dns/doh_test.go‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,5 @@ func TestAdBlockerNotBlockedWhenNoBlocker(t *testing.T) {
312312

313313
func TestLeakDetectorStructure(t *testing.T) {
314314
d := &LeakDetector{}
315-
if d == nil {
316-
t.Fatal("LeakDetector should not be nil")
317-
}
315+
_ = d // ensure d is used; it can never be nil after allocation
318316
}

‎internal/dpi/ai.go‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212
type AIStrategySelector struct {
1313
mu sync.RWMutex
1414
cache map[string]Strategy
15-
defaultStrat Strategy
15+
defaultStrategy Strategy
1616
}
1717

1818
// NewAIStrategySelector creates a new AI strategy selector with a default fallback.
19-
func NewAIStrategySelector(defaultStrat Strategy) *AIStrategySelector {
19+
func NewAIStrategySelector(defaultStrategy Strategy) *AIStrategySelector {
2020
return &AIStrategySelector{
21-
cache: make(map[string]Strategy),
22-
defaultStrat: defaultStrat,
21+
cache: make(map[string]Strategy),
22+
defaultStrategy: defaultStrategy,
2323
}
2424
}
2525

@@ -28,17 +28,17 @@ func NewAIStrategySelector(defaultStrat Strategy) *AIStrategySelector {
2828
func (s *AIStrategySelector) GetStrategyForHost(host string) Strategy {
2929
s.mu.RLock()
3030
defer s.mu.RUnlock()
31-
if strat, ok := s.cache[host]; ok {
32-
return strat
31+
if strategy, ok := s.cache[host]; ok {
32+
return strategy
3333
}
34-
return s.defaultStrat
34+
return s.defaultStrategy
3535
}
3636

3737
// RecordStrategy memorizes a working strategy for a host.
38-
func (s *AIStrategySelector) RecordStrategy(host string, strat Strategy) {
38+
func (s *AIStrategySelector) RecordStrategy(host string, strategy Strategy) {
3939
s.mu.Lock()
4040
defer s.mu.Unlock()
41-
s.cache[host] = strat
41+
s.cache[host] = strategy
4242
}
4343

4444
// ProbeHost tries all strategies against a host and returns the first working one.
@@ -47,18 +47,18 @@ func (s *AIStrategySelector) ProbeHost(ctx context.Context, host string, port in
4747
strategies := AllStrategies()
4848
address := net.JoinHostPort(host, fmt.Sprintf("%d", port))
4949

50-
for _, strat := range strategies {
51-
if strat == StrategyNone {
50+
for _, strategyCandidate := range strategies {
51+
if strategyCandidate == StrategyNone {
5252
continue // skip "none" — prefer fragmentation
5353
}
5454
conn, err := dial(ctx, "tcp", address)
5555
if err != nil {
5656
continue
5757
}
5858
conn.Close()
59-
s.RecordStrategy(host, strat)
60-
return strat, nil
59+
s.RecordStrategy(host, strategyCandidate)
60+
return strategyCandidate, nil
6161
}
6262

63-
return s.defaultStrat, fmt.Errorf("no working strategy found for %s", host)
63+
return s.defaultStrategy, fmt.Errorf("no working strategy found for %s", host)
6464
}

‎internal/dpi/fragment_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ func TestAIStrategySelectorProbeHost(t *testing.T) {
130130
return client, nil
131131
}
132132

133-
strat, err := selector.ProbeHost(context.Background(), "test.com", 443, dial)
134-
if err != nil || strat.Valid() == false {
135-
t.Fatalf("ProbeHost failed: err=%v strat=%s", err, strat)
133+
strategy, err := selector.ProbeHost(context.Background(), "test.com", 443, dial)
134+
if err != nil || strategy.Valid() == false {
135+
t.Fatalf("ProbeHost failed: err=%v strategy=%s", err, strategy)
136136
}
137-
if strat == StrategyNone {
137+
if strategy == StrategyNone {
138138
t.Fatal("probe should not return StrategyNone")
139139
}
140140
cached := selector.GetStrategyForHost("test.com")
141-
if cached != strat {
142-
t.Fatalf("cached = %s, want %s", cached, strat)
141+
if cached != strategy {
142+
t.Fatalf("cached = %s, want %s", cached, strategy)
143143
}
144144
}
145145

@@ -150,12 +150,12 @@ func TestAIStrategySelectorProbeAllFail(t *testing.T) {
150150
return nil, net.ErrClosed
151151
}
152152

153-
strat, err := selector.ProbeHost(context.Background(), "bad.com", 443, dial)
153+
strategy, err := selector.ProbeHost(context.Background(), "bad.com", 443, dial)
154154
if err == nil {
155155
t.Fatal("expected error when all probes fail")
156156
}
157-
if strat != StrategyTCPSegmentation8 {
158-
t.Fatalf("fallback strategy = %s, want %s", strat, StrategyTCPSegmentation8)
157+
if strategy != StrategyTCPSegmentation8 {
158+
t.Fatalf("fallback strategy = %s, want %s", strategy, StrategyTCPSegmentation8)
159159
}
160160
}
161161

‎internal/proxy/chain.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func DialChain(ctx context.Context, upstream *UpstreamProxy, targetNetwork, targ
5656
conn.Close()
5757
return nil, err
5858
}
59+
defer resp.Body.Close()
5960
if resp.StatusCode != http.StatusOK {
6061
conn.Close()
6162
return nil, fmt.Errorf("upstream proxy returned %d", resp.StatusCode)

‎internal/proxy/pac.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
// GeneratePAC creates a PAC file that routes allowed domains through the proxy.
1010
func GeneratePAC(proxyHost string, proxyPort int, domains []string) string {
11-
var conditions []string
11+
conditions := make([]string, 0, len(domains)*2)
1212
for _, d := range domains {
1313
d = strings.TrimPrefix(d, ".")
1414
conditions = append(conditions, fmt.Sprintf(`dnsDomainIs(host, "%s")`, d))

0 commit comments

Comments
 (0)