Golang fmt.Fprint() function examples
package fmt
Fprint formats using the default formats for its operands and writes to w. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.
Golang fmt.Fprint() function usage examples
Example 1:
func (h Hello) ServeHTTP( w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello!")
}
Example 2:
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())
return
case x == nil:
fmt.Fprint(s, "<nil>")
return
}
...
}
Example 3 :
package main
import (
"crypto/sha256"
"fmt"
"encoding/hex"
)
func hash(c string) string {
h := sha256.New()
fmt.Fprint(h, c)
return hex.EncodeToString(h.Sum(nil))
}
func main() {
fmt.Println(hash("abcd"))
}
Reference :
Advertisement
Something interesting
Tutorials
+25k Golang : Create PDF file from HTML file
+40.1k Golang : UDP client server read write example
+19.5k Golang : How to Set or Add Header http.ResponseWriter?
+17.9k Golang : Qt image viewer example
+21.9k Golang : Use TLS version 1.2 and enforce server security configuration over client
+18k Golang : Check if a directory exist or not
+9.6k Golang : How to generate Code 39 barcode?
+18.2k Golang : Get path name to current directory or folder
+31.5k Golang : bufio.NewReader.ReadLine to read file line by line
+7.5k Golang : Dealing with struct's private part
+9.6k Golang : How to extract video or image files from html source code
+15.7k Golang : Get checkbox or extract multipart form data value example