28 lines
845 B
Plaintext
28 lines
845 B
Plaintext
// web server
|
|
|
|
type Foo struct {
|
|
Number int `json:"number"`
|
|
Title string `json:"title"`
|
|
}
|
|
|
|
foo_marshalled, err := json.Marshal(Foo{Number: 1, Title: "test"})
|
|
fmt.Fprint(w, string(foo_marshalled)) // write response to ResponseWriter (w)
|
|
|
|
|
|
first character being uppercase makes it visible to json, then with `json:number` bit tells
|
|
json it's proper name
|
|
|
|
|
|
|
|
* attached to a type (*string) indicates a pointer to the type.
|
|
|
|
* attached to a variable in an assignment (*v = ...) indicates an indirect assignment.
|
|
That is, change the value pointed at by the variable.
|
|
|
|
* attached to a variable or expression (*v) indicates a pointer dereference.
|
|
That is, take the value the variable is pointing at.
|
|
|
|
& attached to a variable or expression (&v) indicates a reference.
|
|
That is, create a pointer to the value of the variable or to the field.
|
|
|