前言:

這個禮拜,總算有點時間可以去參加GTG.也順便多花了點時間研究Go….

筆記:

  
package main

import "fmt"
import "sort"

func main() {

    test := []string{"hello", "world", "z"}
    
    fmt.Println(sort.SearchStrings(test, "hello")) //return 0 which hello could be insert in index 0, before "hello". The same string insert in front of it.
    fmt.Println(sort.SearchStrings(test, ".DS"))   //return 0, ".DS" will be insert in index 0. Not cannot find (-1)
    fmt.Println(sort.SearchStrings(test, "world")) //return 1, reason the same with hello
    fmt.Println(sort.SearchStrings(test, "yDS"))   //return 2, "yDS" before "z" so insert in index 2.

/* Output
0
0
1
2
*/
}
  • [Go gen] A type-driven code generation in Go
    • Git位置
    • 在Go Miami meetup的 demo
    • 簡單介紹:
      • gen 提供了許多好用的type structure,也就是有點類似提供了generic 的功能.你可以透過他的資料型態做更多的資料處理. 在code撰寫上也很簡單.只需要在你的資料前面打上annotation.
  
// +gen slice:"Where,GroupBy[string],Select[Dollars]"
type Person struct {
  Name, Office string
}

func main() {

    ny:= func(p Person) bool {
        return p.Office == "New York"
    }

    fmt.Println(persons.Where(ny))
}

Evan

Attitude is everything