Golang fmt.Println() function examples

package fmt

Println formats using the default formats for its operands and writes to standard output. 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.Println() function usage examples

Example 1 :

 ...
 if err != nil {
 fmt.Println("Error queue binding", err, "queue", queueName, "bindingKey", bindingKey)
 }
 ...

Example 2:

 func ToJson(query *Query) (string, error) {
 var errString string = ""

 if query.Error != nil {
 errString = query.Error.Error()
 }

 d := outputMessage{
 Id: query.Id,
 Command: convertCommandToCommandString(query.Cmd),
 Community: query.Community,
 Oids: query.Oids,
 Timeout: query.Timeout,
 Retries: query.Retries,
 Destination: query.Destination,
 Response: query.Response,
 Error: errString,
 }
 fmt.Println(d)
 b, err := json.Marshal(d)

 if err != nil {
 return "", err
 }
 return string(b), nil
 }

Reference :

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

Advertisement