This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| func main() { | |
| var a []*int | |
| d1 := 100 | |
| d2 := 200 | |
| d3 := 300 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "errors" | |
| "fmt" | |
| "io" | |
| "strings" | |
| "time" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "fmt" | |
| "log" | |
| "net" | |
| "os" | |
| "os/signal" | |
| "time" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| kv := map[string]interface{}{} | |
| kv["A"] = 1 | |
| kv["B"] = "XXX" | |
| kv["C"] = true | |
| for k, v := range kv { | |
| switch v.(type) { | |
| case int: | |
| fmt.Println(k, "INT ", v) | |
| case string: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // parsing JSON by type | |
| func main() { | |
| var Data = []byte(`{"count": 2000}`) | |
| var result map[string]interface{} | |
| var decoder = json.NewDecoder(bytes.NewBuffer(Data)) | |
| decoder.UseNumber() | |
| if err := decoder.Decode(&result); err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Make | |
| m := make(map[string]int) | |
| m1 := new(map[string]int) | |
| var m2 map[string]int | |
| m3 := map[string]int{"apple": 99, "orange": 100} | |
| // Insert data | |
| m3["carrot"] = 101 | |
| // Delete data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "sync" | |
| type Init struct { | |
| message string | |
| init sync.Once | |
| } | |
| func (d *Init) Run() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "sync" | |
| ) | |
| var i int | |
| func main(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "sync" | |
| var ( | |
| mu sync.Mutex | |
| balance int | |
| ) | |
| func Deposit(amount int) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| ) | |
| func main() { | |
| db := database{"AAA": 50, "BBB": 5 , "CCC" : 77} |
NewerOlder