我在戈朗找到了一个印刷颜色的包裹。然而,它没有简单的方式印刷没有颜色。当我的代码变得越来越混乱,因为充满了打印语句,我想重写它。但是,我不知道如何在函数中创建fstring。
它在我的代码中的外观:
color.HEX("#B0DFE5").Print("[" + time.Now().Format("15:04:05") +"] ")
color.HEX("#FFFFFF").Printf("Changed %s to %s\n", name, new_name) 我为普通版画创作的东西:
func cprintInfo(message string) {
color.HEX("#B0DFE5").Print("[!] ")
color.HEX("#FFFFFF").Printf(message + "\n")
}我想要创造的是:
cfprintInfo("Hello %s", world)
// Hello world发布于 2022-01-05 20:58:56
Printf()需要一个格式字符串和(可选)参数:
func (c RGBColor) Printf(format string, a ...interface{})所以模仿:
func cfprintInfo(format string, args ...interface{}) {
color.HEX("#B0DFE5").Print("[!] ")
color.HEX("#FFFFFF").Printf(format, args...)
}https://stackoverflow.com/questions/70599464
复制相似问题