2013-07-10 86 views
1

有什麼方法可以使Warn函數起作用?如何將可變參數傳遞給其他函數

func Warn(s string, args ...interface{}) { 
    log.Printf("warn: "+s, args) 
} 

func main() { 
    Warn("%d apples, %s ", 10, "good") //it should output the same as below 
    log.Printf("%d apples, %s ", 10, "good") 
} 

輸出:

2009/11/10 23:00:00 warn: [10 %!d(string=good)] apples, %s(MISSING) 
2009/11/10 23:00:00 10 apples, good 

我試圖使這項工作:http://play.golang.org/p/W62f2NGDUe

回答

7

明白了:

func Warn(s string, args ...interface{}) { 
    log.Printf("warn: "+s, args...) 
} 

現在,它的工作原理。

相關問題