Golang: fmt, variadic args and %!(EXTRA type=value) error

The error was between the chair and keyboard. I mixed up the following interfaces:

func Print(v ...interface{})
func Printf(format string, v ...interface{})

Some of my code was calling the library without a format string.See here for a more detailed example: http://play.golang.org/p/Xx79qujaFp


I can't reproduce this behavior. Are you sure it's not a simple error that you forgot to show here?

https://play.golang.org/p/-jtmll17Xj

package main

import "fmt"

func Info(format string, args ...interface{}){
    msg := fmt.Sprintf(format, args...)
    fmt.Print(msg)
}

func main() {
    Info("Hello %s", "World")
}

Prints

Hello World

According to the fmt docs, %!(EXTRA string=WORLD) is added to the string when you pass extra parameters, unexpected by the format. Maybe you are using the format string "Hello World" instead of "Hello %s", or passing the argument twice?

Tags:

Go