处理文本文件模板,然后输出到文件
package main import ( "fmt" "bytes" "text/template" ) type Inventory struct { Count []int } func main() { sweaters := Inventory{[]int{43,32,543}} tmpl, err := template.ParseFiles("mb.txt") if err != nil { panic(err) } var doc bytes.Buffer err = tmpl.Execute(&doc, sweaters) if err != nil { panic(err) } s := doc.String() fmt.Println(s) }
参考链接:https://groups.google.com/forum/#!topic/golang-nuts/dSFHCV-e6Nw
读出所有key
package main import ( "fmt" "github.com/garyburd/redigo/redis" ) func main() { // maxConnections := 10 // redisPool := redis.NewPool(func() (redis.Conn, error) { // con, err := redis.Dial("tcp", "127.0.0.1") // con.Do("SELECT", 0) // if err != nil { // return nil, err // } // return con, err // }, maxConnections) // fmt.Println("Redis Connection Established...!") // con := redisPool.Get() // // //defer con.Close() // fmt.Println("Redis Connected...!") //var sl []string = make([]string, len, cap) // var ab interface{} // ab, errA := con.Do("Keys", "*") // fmt.Println(ab) // fmt.Println(errA) con, err := redis.Dial("tcp", "127.0.0.1:6379") if err != nil { fmt.Println(err) return } defer con.Close() keys, err := redis.Strings(con.Do("KEYS", "s:*")) if err != nil { // handle error } for _, key := range keys { fmt.Println(key) } }
参考链接:http://stackoverflow.com/questions/31473676/get-all-keys-from-redis-in-go