我在 golang 中找到了一個用于列印顏色的包。然而,它具有列印的沒有簡單的方法,沒有顏色。隨著我的代碼因為充滿了列印陳述句而變得更加混亂,我想重寫它。但是,我不知道如何在函式中創建 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
uj5u.com熱心網友回復:
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://www.uj5u.com/net/404476.html
標籤:
