hic003cih / Golang

0 stars 0 forks source link

7 #34

Open hic003cih opened 4 years ago

hic003cih commented 4 years ago
package main

import (
    "fmt"
)

func main() {
    x := 42
    fmt.Println(x)
    fmt.Println(&x)
}
package main

import (
    "fmt"
)

type person struct {
    name string
}

func main() {
    p1 := person{
        name: "James Bond",
    }
    fmt.Println(p1)
    changeMe(&p1)
    fmt.Println(p1)
}

func changeMe(p *person) {
    p.name = "Miss Moneypenny"
    // (*p).name = "Miss Moneyp"
}
hic003cih commented 4 years ago

Here is an example of how you marshal data in Go to JSON. Also important, this video shows how the case of an identifier - lowercase or uppercase, determines whether or not the data can be exported. Here is an example of how you marshal data in Go to JSON. Also important, this video shows how the case of an identifier - lowercase or uppercase, determines whether or not the data can be exported. Here is an example of how you marshal data in Go to JSON. Also important, this video shows how the case of an identifier - lowercase or uppercase, determines whether or not the data can be exported.

package main

import (
    "encoding/json"
    "fmt"
)

type person struct {
    First string
    Last  string
    Age   int
}

func main() {
    p1 := person{
        First: "James",
        Last:  "Bond",
        Age:   32,
    }

    p2 := person{
        First: "Miss",
        Last:  "Moneypenny",
        Age:   27,
    }

    people := []person{p1, p2}

    fmt.Println(people)

    bs, err := json.Marshal(people)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(string(bs))
}