mirror of
https://github.com/SourceFellows/gobuch.git
synced 2025-08-02 13:02:15 +02:00
initial import
This commit is contained in:
23
microservices/jsonhandling/main.go
Normal file
23
microservices/jsonhandling/main.go
Normal file
@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Customer struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Firstname string `json:"first,omitempty"`
|
||||
Lastname string `json:"last,omitempty"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
customer := &Customer{ID: 1,
|
||||
Firstname: "Hans", Lastname: "Wurst"}
|
||||
bites, _ := json.Marshal(customer)
|
||||
fmt.Println(string(bites))
|
||||
|
||||
customer2 := &Customer{}
|
||||
json.Unmarshal(bites, customer2)
|
||||
fmt.Println(customer2.Firstname)
|
||||
}
|
Reference in New Issue
Block a user