Sunday, 12 May 2019

Go language: Print structure with field names


Format specifier ‘%+v’ is used to print the structure with field names.

Example
fmt.Printf("%+v\n", emp)

App.go
package main

import "fmt"

type Employee struct {
	FirstName string
	LastName  string
	id        int
}

func main() {
	emp := Employee{"Krishna", "Gurram", 123}

	fmt.Printf("%+v\n", emp)
}

Output
{FirstName:Krishna LastName:Gurram id:123}



Previous                                                 Next                                                 Home

No comments:

Post a Comment