编辑代码

package main
import "fmt"

type Person struct {
    name string
    age  int8
}


type User struct {
	Name string
	Age  int
}

func NewPerson(name string, age int8) *Person {
    return &Person{
        name: name,
        age:  age,
    }
}

func (p *Person) SetAge(newAge int8) {
    p.age = newAge
}

func main () {
    //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
    p1 := NewPerson("测试", 25)
    fmt.Println(p1.age) // 25
    p1.SetAge(30)
    fmt.Println(p1.age) // 30
    
    user := User{
		Name: "张三",
		Age:  95,
	}
    fmt.Printf("%+v\n", user)
}