golang - print all fields in a s truct



This is how to print out all fields name in a struct.


import (
    "fmt"
    "log"
)

type employee struct {
    name string
    email string
}

func main() {

    a := employee{}
    fmt.Printf("%+v\n", a)

// To get all the values
fmt.Printf("%#v\n", a)
}



This is the output

{name: email:}

{name: 'username' ,email:'email@address'}

Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm