Golang fmt.State type examples
package fmt
State represents the printer state passed to custom formatters. It provides access to the io.Writer interface plus information about the flags and options for the operand's format specifier.
Golang fmt.State type usage examples
Example 1:
var s fmt.State
sign := ""
switch {
case s.Flag('+'):
sign = "+"
case s.Flag(' '):
sign = " "
}
Example 2:
func writeMany(text string, st fmt.State, counter int) {
if len(text) > 0 {
b := []byte(text)
for ; counter > 0; counter-- {
st.Write(b)
}
}
}
Example 3:
var f fmt.State
var s string
if w, ok := f.Width(); ok {
s += fmt.Sprintf("%d", w)
}
Reference :
Advertisement
Something interesting
Tutorials
+24.1k Golang : Upload to S3 with official aws-sdk-go package
+6.5k Golang : Map within a map example
+9.6k Golang : Read file with ioutil
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?
+5.8k Cash Flow : 50 days to pay your credit card debt
+5.3k Golang : Pad file extension automagically
+41k Golang : How to check if a string contains another sub-string?
+10.6k Golang : Bubble sort example
+26.8k Golang : Convert file content into array of bytes
+27.4k Golang : Convert CSV data to JSON format and save to file
+5.4k Golang *File points to a file or directory ?