fmt.println code example
Example 1: go format string
s := fmt.Sprintf("string: %s number: %d time: %v", "string", 1, time.Now())
Example 2: print in golang
package Main
import ("fmt")
func main(){
fmt.Print("this message will be printed without a linefeed at the end")
fmt.Println("this message will be printed with a linefeed a the end")
fmt.Printf("You can also use %s formatings with Printf \n (PS : this message won't end with a line feed)","multiples")
}
Example 3: format string go
fmt.Sprintf("foo: %s", bar)
Example 4: %+v in golang
%v the value in a default format
when printing structs, the plus flag (%+v) adds field names
%#v a Go-syntax representation of the value
%T a Go-syntax representation of the type of the value
%% a literal percent sign; consumes no value
Example 5: format string go
return fmt.Sprintf("at %v, %s", e.When, e.What)