Golang fmt.Fprintf() function examples
**package fmt***
Fprintf formats according to a format specifier and writes to w. It returns the number of bytes written and any write error encountered.
Golang fmt.Fprintf() function usage examples
Example 1:
func (x *Int) Format(s fmt.State, ch rune) {
cs := charset(ch)
// special cases
switch {
case cs == "":
// unknown format
fmt.Fprintf(s, "%%!%c(big.Int=%s)", ch, x.String()) //<--- here
return
case x == nil:
fmt.Fprint(s, "<nil>")
return
}
...
Example 2:
...
var helptext = `Usage: gosteno-prettify [OPTS] [FILE(s)]
Parses json formatted log lines from FILE(s), or stdin,
and displays a more human friendly version of each line to stdout.
Examples :
gosteno-prettify f - g
Prettify f's contents, then standard input, then g's contents.
gosteno-prettify
Prettify contents of stdin.
Options:
-h
Display help
-a
Omit location and data in order to provide well-aligned logs
-s
Do not complain about errors in parsing logs
`
flag.Usage = func() {
fmt.Fprintf(os.Stderr, helptext)
}
...
Reference :
Advertisement
Something interesting
Tutorials
+21.5k Golang : How to read float value from standard input ?
+6.2k Golang & Javascript : How to save cropped image to file on server
+9.6k Golang : Validate IPv6 example
+18.7k Unmarshal/Load CSV record into struct in Go
+11.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+20.6k Golang : Secure(TLS) connection between server and client
+12.3k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+7k Golang : Levenshtein distance example
+14.8k Golang : Get URI segments by number and assign as variable example
+6.8k Golang : Join lines with certain suffix symbol example
+19.2k Golang : Populate dropdown with html/template example
+9.4k Golang : Apply Histogram Equalization to color images