Go 自学:struct结构体

以下代码展示如何建立一个结构体struct。
我们可以使用%+v查看结构体的详情。

package main

import (
	"fmt"
)

func main() {
	Jeff := User{"Jeff", "[email protected]", true, 16}
	fmt.Println((Jeff))
	fmt.Printf("Jeff details are: %+v\n", Jeff)
	fmt.Printf("Name is %v and email is %v.", Jeff.Name, Jeff.Email)

}

type User struct {
	Name   string
	Email  string
	Status bool
	Age    int
}

输出为:
{Jeff [email protected] true 16}
Jeff details are: {Name:Jeff Email:[email protected] Status:true Age:16}
Name is Jeff and email is [email protected].

你可能感兴趣的:(golang,golang)