-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve(hosts): use more meaningful name for host name #330
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,17 @@ func (hc *HostConfig) getBool(i *comm.Item) bool { | |
return v.(bool) | ||
} | ||
|
||
func (hc *HostConfig) getName() string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个函数可以去掉,每个配置项都提供了一个默认值的钩子,你可以在上面做事情,可以参见 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the guidance. Following your advice, I have re-implemented this functionality in the hc_item. If there are further areas that need modification, I would appreciate your guidance once again. |
||
res := hc.GetHost() | ||
if res != "" { | ||
return res | ||
} | ||
|
||
return hc.getString(CONFIG_NAME) | ||
} | ||
|
||
func (hc *HostConfig) GetHost() string { return hc.getString(CONFIG_HOST) } | ||
func (hc *HostConfig) GetName() string { return hc.getName() } | ||
func (hc *HostConfig) GetHostname() string { return hc.getString(CONFIG_HOSTNAME) } | ||
func (hc *HostConfig) GetSSHHostname() string { return hc.getString(CONFIG_SSH_HOSTNAME) } | ||
func (hc *HostConfig) GetSSHPort() int { return hc.getInt(CONFIG_SSH_PORT) } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,12 @@ var ( | |
nil, | ||
) | ||
|
||
CONFIG_NAME = itemset.Insert( | ||
"name", | ||
comm.REQUIRE_STRING, | ||
false, | ||
nil, | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注意换行 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my mistake, i will fix it |
||
CONFIG_HOSTNAME = itemset.Insert( | ||
"hostname", | ||
comm.REQUIRE_STRING, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,9 +141,9 @@ func (hc *HostConfig) Build() error { | |
} | ||
|
||
privateKeyFile := hc.GetPrivateKeyFile() | ||
if len(hc.GetHost()) == 0 { | ||
if len(hc.GetName()) == 0 { | ||
return errno.ERR_HOST_FIELD_MISSING. | ||
F("hosts[%d].host = nil", hc.sequence) | ||
F("hosts[%d].host/name = nil", hc.sequence) | ||
} else if len(hc.GetHostname()) == 0 { | ||
return errno.ERR_HOSTNAME_FIELD_MISSING. | ||
F("hosts[%d].hostname = nil", hc.sequence) | ||
|
@@ -206,12 +206,12 @@ func ParseHosts(data string) ([]*HostConfig, error) { | |
return nil, err | ||
} | ||
|
||
if _, ok := exist[hc.GetHost()]; ok { | ||
return nil, errno.ERR_DUPLICATE_HOST. | ||
F("duplicate host: %s", hc.GetHost()) | ||
if _, ok := exist[hc.GetName()]; ok { | ||
return nil, errno.ERR_DUPLICATE_NAME. | ||
F("duplicate host: %s", hc.GetName()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
hcs = append(hcs, hc) | ||
exist[hc.GetHost()] = true | ||
exist[hc.GetName()] = true | ||
} | ||
build.DEBUG(build.DEBUG_HOSTS, hosts) | ||
return hcs, nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the host printed here need to be replaced?