@kjk1/

gobook struct declare

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.28765734059510595","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImZtdCIKKQoKLy8gOnNob3cgc3RhcnQKLy8gVXNlciBkZXNjcmliZXMgYSB1c2VyCnR5cGUgVXNlciBzdHJ1Y3QgewoJRmlyc3ROYW1lLCBMYXN0TmFtZSBzdHJpbmcKCUVtYWlsICAgICAgICAgICAgICAgc3RyaW5nCglBZ2UgICAgICAgICAgICAgICAgIGludAoJdXNlcklEICAgICAgICAgICAgICBpbnQKfQoKLy8gRnVsbE5hbWUgcmV0dXJucyBmdWxsIG5hbWUgb2YgYSB1c2VyCmZ1bmMgKHUgKlVzZXIpIEZ1bGxOYW1lKCkgc3RyaW5nIHsKCXJldHVybiBmbXQuU3ByaW50ZigiJXMgJXMiLCB1LkZpcnN0TmFtZSwgdS5MYXN0TmFtZSkKfQoKZnVuYyBtYWluKCkgewoJLy8gemVybyB2YWx1ZSBvZiBzdHJ1Y3QKCXZhciB1IFVzZXIKCWZtdC5QcmludGYoInU6ICUjdlxuXG4iLCB1KQoKCS8vIHB1IGlzICpVc2VyIGkuZS4gYSBwb2ludGVyIHRvIFVzZXIgc3RydWN0CglwdSA6PSBuZXcoVXNlcikKCXB1LkFnZSA9IDMzCglmbXQuUHJpbnRmKCIqcHU6ICUjdlxuIiwgKnB1KQoKCS8vICZVc2Vye30gaXMgdGhlIHNhbWUgYXMgbmV3KFVzZXIpCglwdSA9ICZVc2Vye30KCXB1LkFnZSA9IDE4CglmbXQuUHJpbnRmKCIqcHU6ICUjdlxuIiwgKnB1KQoKCXB1LkZpcnN0TmFtZSwgcHUuTGFzdE5hbWUgPSAiSmFuZSIsICJEb2UiCglmbXQuUHJpbnRmKCJwdS5GdWxsTmFtZSgpOiAlc1xuIiwgcHUuRnVsbE5hbWUoKSkKfQoKLy8gOnNob3cgZW5k"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main

import (
	"fmt"
)

// :show start
// User describes a user
type User struct {
	FirstName, LastName string
	Email               string
	Age                 int
	userID              int
}

// FullName returns full name of a user
func (u *User) FullName() string {
	return fmt.Sprintf("%s %s", u.FirstName, u.LastName)
}

func main() {
	// zero value of struct
	var u User
	fmt.Printf("u: %#v\n\n", u)

	// pu is *User i.e. a pointer to User struct
	pu := new(User)
	pu.Age = 33
	fmt.Printf("*pu: %#v\n", *pu)

	// &User{} is the same as new(User)
	pu = &User{}
	pu.Age = 18
	fmt.Printf("*pu: %#v\n", *pu)

	pu.FirstName, pu.LastName = "Jane", "Doe"
	fmt.Printf("pu.FullName(): %s\n", pu.FullName())
}

// :show end