商君

导航

2018年10月26日 #

Go Example--格式化字符串

摘要: ```go package main import ( "fmt" "os" ) type point struct { x, y int } func main() { p := point{1, 2} fmt.Printf("%v\n", p) fmt.Printf("%+v\n", p) fmt.Printf("%#v\n", p) fmt.Printf("%T\n",... 阅读全文

posted @ 2018-10-26 20:22 漫步者01 阅读(87) 评论(0) 推荐(0)

Go Example--strings

摘要: ```go package main import ( "fmt" s "strings" ) var p = fmt.Println func main() { //strings标准库包含的函数 p("Contains: ", s.Contains("test", "es")) p("Count:", s.Count("test", "t")) p("HasPrefix", ... 阅读全文

posted @ 2018-10-26 20:13 漫步者01 阅读(73) 评论(0) 推荐(0)

Go Example--组合函数

摘要: ```go package main import ( "fmt" "strings" ) func Index(vs []string, t string) int { for i, v := range vs { if v == t { return i } } return -1 } func Include(vs []string, t string) boo... 阅读全文

posted @ 2018-10-26 20:02 漫步者01 阅读(72) 评论(0) 推荐(0)

Go Example--defer

摘要: ```go package main import ( "fmt" "os" ) func main() { f := createFile("/tmp/defer.txt") //在函数退出时调用defer defer closeFile(f) writeFile(f) } func createFile(p string) *os.File { fmt.Println("c... 阅读全文

posted @ 2018-10-26 14:28 漫步者01 阅读(83) 评论(0) 推荐(0)