Golang fmt.Fprintln() function examples

package fmt

Fprintln formats using the default formats for its operands and writes to w. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

Golang fmt.Fprintln() function usage examples

Example 1 :

 c := make(chan os.Signal, 1)
 signal.Notify(c, os.Interrupt, syscall.SIGTERM)

 <-c
 fmt.Fprintln(os.Stderr, "\nReceived second interrupt.  Shutting down.")
 os.Exit(1)

Example 2 :

 http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 fmt.Fprintln(w, "Hello World! ")
 })

Reference :

http://golang.org/pkg/fmt/#Fprintln

Advertisement