mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-02 21:52:51 +08:00
refactor: improve code clarity and logging functionality
- Add a comment to clarify the purpose of the `format` function - Add a comment to clarify the purpose of the `log` function - Modify the `log` function to always print the message, removing the previous conditional statement Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
parent
c7dd9890fa
commit
80cecf1ed3
@ -155,20 +155,23 @@ loop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// format string
|
||||||
func (p Plugin) format(format string, args ...string) string {
|
func (p Plugin) format(format string, args ...string) string {
|
||||||
r := strings.NewReplacer(args...)
|
r := strings.NewReplacer(args...)
|
||||||
return r.Replace(format)
|
return r.Replace(format)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// log output to console
|
||||||
func (p Plugin) log(host string, message ...interface{}) {
|
func (p Plugin) log(host string, message ...interface{}) {
|
||||||
if p.Writer == nil {
|
if p.Writer == nil {
|
||||||
p.Writer = os.Stdout
|
p.Writer = os.Stdout
|
||||||
}
|
}
|
||||||
if count := len(p.Config.Host); count == 1 {
|
if count := len(p.Config.Host); count == 1 {
|
||||||
fmt.Fprintf(p.Writer, "%s", fmt.Sprintln(message...))
|
fmt.Fprintf(p.Writer, "%s", fmt.Sprintln(message...))
|
||||||
} else {
|
return
|
||||||
fmt.Fprintf(p.Writer, "%s: %s", host, fmt.Sprintln(message...))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(p.Writer, "%s: %s", host, fmt.Sprintln(message...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exec executes the plugin.
|
// Exec executes the plugin.
|
||||||
|
Loading…
Reference in New Issue
Block a user