Declare a struct:
1 2 3 4 5 6 7 8 9 type person struct { name, lastname string age int } var alice struct { name, lastname string age int } Struct instance:
1 2 3 4 5 6 7 8 9 picasso := person{ name: "Pablo", lastname: "Picasso", age: 91, } alice.Read standard input by line:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import ( "bufio" "os" "fmt" ) func main() { // New scanner to read from stdin. // By default it reads line.My notes of 1% Better Every Day - James Clear at ConvertKit Craft + Commerce 2017 talk.
The aggregation of marginal gains. To explain this, speaker talks about bicycle group example that work on small improvement to achieve an goal.
Improve 1% each day that compound to end up 37% times better at end of year.Package ioutil implements I/O functions.
1 import "ioutil" Read file:
1 config, error := ioutil.ReadFile("/etc/config") Write to file:
1 error := ioutil.WriteFile("/etc/config", config, 0644) Read direcrtory:
1 2 3 4 5 6 7 8 9 10 11 12 // ioutil.Declare a map:
1 2 3 4 5 6 7 8 9 // Nil map: Read-Only var di map[string]string dict := map[string]string{ "good": "iyi", "great": "harika", "perfect": "mükemmel", } Delete an element of the map using delete builtin:
1 delete(dict, "awesome") Retrieve an value from map: