Skip to content

Commit 82bca54

Browse files
committed
fix goconst
1 parent 0677d63 commit 82bca54

7 files changed

Lines changed: 43 additions & 32 deletions

File tree

pkg/config/config_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (m *Manager) DeleteConfigFile(targetPath string) error {
132132
for _, astHost := range cfg.Hosts {
133133
val := reflect.ValueOf(astHost)
134134
isImplicit := false
135-
if val.Kind() == reflect.Ptr && !val.IsNil() {
135+
if val.Kind() == reflect.Pointer && !val.IsNil() {
136136
elem := val.Elem()
137137
implicitField := elem.FieldByName("implicit")
138138
if implicitField.IsValid() && implicitField.Kind() == reflect.Bool && implicitField.Bool() {

pkg/config/editor.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (m *Manager) UpdateHost(originalAlias string, h *Host) error {
9999
for _, astHost := range decoded.Hosts {
100100
val := reflect.ValueOf(astHost)
101101
isImplicit := false
102-
if val.Kind() == reflect.Ptr && !val.IsNil() {
102+
if val.Kind() == reflect.Pointer && !val.IsNil() {
103103
elem := val.Elem()
104104
implicitField := elem.FieldByName("implicit")
105105
if implicitField.IsValid() && implicitField.Kind() == reflect.Bool && implicitField.Bool() {
@@ -239,20 +239,20 @@ func buildHostString(h *Host) string {
239239
var sb strings.Builder
240240
fmt.Fprintf(&sb, "Host %s\n", h.Alias)
241241
if h.Name != "" {
242-
fmt.Fprintf(&sb, " HostName %s\n", h.Name)
242+
fmt.Fprintf(&sb, " %s %s\n", keyHostName, h.Name)
243243
}
244244
if h.User != "" {
245-
fmt.Fprintf(&sb, " User %s\n", h.User)
245+
fmt.Fprintf(&sb, " %s %s\n", keyUser, h.User)
246246
}
247247
if h.Port != "" {
248-
fmt.Fprintf(&sb, " Port %s\n", h.Port)
248+
fmt.Fprintf(&sb, " %s %s\n", keyPort, h.Port)
249249
}
250250
if h.IdentityFile != "" {
251-
fmt.Fprintf(&sb, " IdentityFile %s\n", h.IdentityFile)
251+
fmt.Fprintf(&sb, " %s %s\n", keyIdentityFile, h.IdentityFile)
252252
}
253253

254254
for k, v := range h.Properties {
255-
if k != "HostName" && k != "User" && k != "Port" && k != "IdentityFile" && v != "" {
255+
if k != keyHostName && k != keyUser && k != keyPort && k != keyIdentityFile && v != "" {
256256
fmt.Fprintf(&sb, " %s %s\n", k, v)
257257
}
258258
}

pkg/config/keys.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package config
2+
3+
const (
4+
keyHostName = "HostName"
5+
keyUser = "User"
6+
keyPort = "Port"
7+
keyIdentityFile = "IdentityFile"
8+
keyForwardAgent = "ForwardAgent"
9+
keyProxyJump = "ProxyJump"
10+
)

pkg/config/manager.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (m *Manager) GetHosts() []*Host {
6262
for _, astHost := range cfg.Hosts {
6363
// Skip the implicit default "Host *" block added by the parser
6464
val := reflect.ValueOf(astHost)
65-
if val.Kind() == reflect.Ptr && !val.IsNil() {
65+
if val.Kind() == reflect.Pointer && !val.IsNil() {
6666
elem := val.Elem()
6767
implicitField := elem.FieldByName("implicit")
6868
if implicitField.IsValid() && implicitField.Kind() == reflect.Bool && implicitField.Bool() {
@@ -106,7 +106,7 @@ func (m *Manager) GetHosts() []*Host {
106106

107107
// Inject inherited properties from matching wildcard blocks.
108108
if !isWildcard && globalConfig != nil {
109-
for _, key := range []string{"HostName", "User", "Port", "IdentityFile", "ForwardAgent", "ProxyJump"} {
109+
for _, key := range []string{keyHostName, keyUser, keyPort, keyIdentityFile, keyForwardAgent, keyProxyJump} {
110110
if _, explicit := h.Properties[key]; !explicit {
111111
if resolvedVal, err := globalConfig.Get(alias, key); err == nil && resolvedVal != "" {
112112
h.ResolvedProperties[key] = resolvedVal
@@ -116,17 +116,17 @@ func (m *Manager) GetHosts() []*Host {
116116
}
117117

118118
// Update resolved shortcuts.
119-
if h.Name == "" && h.ResolvedProperties["HostName"] != "" {
120-
h.Name = h.ResolvedProperties["HostName"]
119+
if h.Name == "" && h.ResolvedProperties[keyHostName] != "" {
120+
h.Name = h.ResolvedProperties[keyHostName]
121121
}
122-
if h.User == "" && h.ResolvedProperties["User"] != "" {
123-
h.User = h.ResolvedProperties["User"]
122+
if h.User == "" && h.ResolvedProperties[keyUser] != "" {
123+
h.User = h.ResolvedProperties[keyUser]
124124
}
125-
if h.Port == "" && h.ResolvedProperties["Port"] != "" {
126-
h.Port = h.ResolvedProperties["Port"]
125+
if h.Port == "" && h.ResolvedProperties[keyPort] != "" {
126+
h.Port = h.ResolvedProperties[keyPort]
127127
}
128-
if h.IdentityFile == "" && h.ResolvedProperties["IdentityFile"] != "" {
129-
h.IdentityFile = h.ResolvedProperties["IdentityFile"]
128+
if h.IdentityFile == "" && h.ResolvedProperties[keyIdentityFile] != "" {
129+
h.IdentityFile = h.ResolvedProperties[keyIdentityFile]
130130
}
131131

132132
hosts = append(hosts, h)

pkg/config/manager_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ Host 10.200.1.46
6464
assert.Equal(t, "~/.ssh/keys/work_rsa", prodHost.IdentityFile)
6565
// Verify prodHost inherited port 2222 from wildcard Host *
6666
assert.Equal(t, "2222", prodHost.ResolvedProperties["Port"])
67-
assert.Equal(t, "yes", prodHost.ResolvedProperties["ForwardAgent"])
67+
assert.Equal(t, "yes", prodHost.ResolvedProperties[keyForwardAgent])
6868

6969
// Verify dbHost does not have alias (its alias is the IP itself)
7070
assert.NotNil(t, dbHost)
7171
assert.Equal(t, "10.200.1.46", dbHost.Alias)
7272
// dbHost should inherit User, Port, and ForwardAgent from wildcard
7373
assert.Equal(t, "default_user", dbHost.User)
7474
assert.Equal(t, "2222", dbHost.Port)
75-
assert.Equal(t, "yes", dbHost.ResolvedProperties["ForwardAgent"])
75+
assert.Equal(t, "yes", dbHost.ResolvedProperties[keyForwardAgent])
7676
}
7777

7878
// TestManagerIncludes tests glob inclusion and recursive parsing.
@@ -130,7 +130,7 @@ Host my-host
130130
User: "admin",
131131
Port: "22",
132132
Properties: map[string]string{
133-
"ForwardAgent": "yes",
133+
keyForwardAgent: "yes",
134134
},
135135
}
136136
err = mgr.AddHost(primaryPath, newHost)
@@ -153,7 +153,7 @@ Host my-host
153153
assert.Equal(t, "192.168.1.10", addedHost.Name)
154154
assert.Equal(t, "admin", addedHost.User)
155155
assert.Equal(t, "22", addedHost.Port)
156-
assert.Equal(t, "yes", addedHost.Properties["ForwardAgent"])
156+
assert.Equal(t, "yes", addedHost.Properties[keyForwardAgent])
157157

158158
// 2. Update host
159159
updatedHost := &Host{
@@ -162,8 +162,8 @@ Host my-host
162162
User: "root",
163163
Port: "222",
164164
Properties: map[string]string{
165-
"ForwardAgent": "no",
166-
"ProxyJump": "jump-box",
165+
keyForwardAgent: "no",
166+
"ProxyJump": "jump-box",
167167
},
168168
}
169169
err = mgr2.UpdateHost("added-host", updatedHost)
@@ -186,7 +186,7 @@ Host my-host
186186
assert.Equal(t, "192.168.1.15", foundUpdated.Name)
187187
assert.Equal(t, "root", foundUpdated.User)
188188
assert.Equal(t, "222", foundUpdated.Port)
189-
assert.Equal(t, "no", foundUpdated.Properties["ForwardAgent"])
189+
assert.Equal(t, "no", foundUpdated.Properties[keyForwardAgent])
190190
assert.Equal(t, "jump-box", foundUpdated.Properties["ProxyJump"])
191191

192192
// 3. Delete host

pkg/tui/constants.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package tui
2+
3+
const (
4+
actionAdd = "add"
5+
actionEdit = "edit"
6+
tabAll = "All"
7+
keyEsc = "esc"
8+
keyEnter = "enter"
9+
)

pkg/tui/model.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ const (
2323
ModeCommand
2424
)
2525

26-
const (
27-
actionAdd = "add"
28-
actionEdit = "edit"
29-
tabAll = "All"
30-
keyEsc = "esc"
31-
keyEnter = "enter"
32-
)
33-
3426
// Model holds the state machine parameters for the Bubble Tea application loop.
3527
type Model struct {
3628
Manager *config.Manager

0 commit comments

Comments
 (0)