随笔分类 -  golibs

摘要:```go package main import ( "fmt" "os" ) func main() { f, err := os.Open("test.file") if err != nil { panic(err) } fi, err := f.Stat() if err != nil { panic(err) } fmt.Printf("File n... 阅读全文
posted @ 2018-03-23 23:24 cucy_to 阅读(103) 评论(0) 推荐(0)
摘要:```go package main import ( "encoding/json" "fmt" "strings" ) const js = ` [{ "name":"Axel", "lastname":"Fooley" }, { "name":"Tim", "lastname":"Burton 阅读全文
posted @ 2018-03-22 01:13 cucy_to 阅读(116) 评论(0) 推荐(0)
摘要:```go package main import ( "archive/zip" "bytes" "fmt" "io" "io/ioutil" "log" "os" ) func main() { var buff bytes.Buffer // Compress content zipW := zip.NewWriter(&buff) f, err := zip... 阅读全文
posted @ 2018-03-22 01:08 cucy_to 阅读(136) 评论(0) 推荐(0)
摘要:```go package main import ( "bytes" "encoding/gob" "fmt" ) type User struct { FirstName string LastName string Age int Active bool } func (u User) Str 阅读全文
posted @ 2018-03-22 01:07 cucy_to 阅读(136) 评论(0) 推荐(0)
摘要:```go package main import ( "io" "log" "os" "os/exec" ) func main() { pReader, pWriter := io.Pipe() cmd := exec.Command("echo", "Hello Go!\nThis is example") cmd.Stdout = pWriter go func(... 阅读全文
posted @ 2018-03-22 01:05 cucy_to 阅读(166) 评论(0) 推荐(0)
摘要:```go package main import "io" import "bytes" import "os" import "fmt" func main() { buf := bytes.NewBuffer([]byte{}) f, err := os.OpenFile("sample.txt", os.O_CREATE|os.O_RDWR, os.ModePerm) if e... 阅读全文
posted @ 2018-03-22 01:02 cucy_to 阅读(382) 评论(0) 推荐(1)
摘要:```go package main import ( "bytes" "encoding/binary" "fmt" ) func main() { // Writing binary values buf := bytes.NewBuffer([]byte{}) if err := binary.Write(buf, binary.BigEndian, 1.004); er... 阅读全文
posted @ 2018-03-22 00:59 cucy_to 阅读(129) 评论(0) 推荐(0)
摘要:```go package main import ( "errors" "fmt" "os" ) const lineLegth = 25 func main() { f, e := os.OpenFile("flatfile.txt", os.O_RDWR|os.O_CREATE, os.ModePerm) if e != nil { panic(e) } defe... 阅读全文
posted @ 2018-03-22 00:57 cucy_to 阅读(157) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "io/ioutil" "os" "golang.org/x/text/encoding/charmap" ) func main() { // Write the string // encoded to Windows-1252 encoder := charmap.Windows1252.NewEnc... 阅读全文
posted @ 2018-03-22 00:54 cucy_to 阅读(111) 评论(0) 推荐(0)
摘要:```go package main import "os" import "bufio" import "bytes" import "fmt" import "io/ioutil" func main() { fmt.Println("### Read as reader ###") f, err := os.Open("temp/file.txt") if err != ni... 阅读全文
posted @ 2018-03-22 00:51 cucy_to 阅读(123) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "io" "io/ioutil" "os" ) func main() { f, err := os.Open("temp/file.txt") if err != nil { panic(err) } c, err := ioutil.ReadAll(f) if err != nil { pa... 阅读全文
posted @ 2018-03-22 00:48 cucy_to 阅读(300) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "io" "os" ) func main() { // Simply write string io.WriteString(os.Stdout, "This is string to standard output.\n") i 阅读全文
posted @ 2018-03-22 00:45 cucy_to 阅读(131) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" ) func main() { var name string fmt.Println("What is your name?") fmt.Scanf("%s\n", &name) var age int fmt.Println("What is your age?") fmt.Scanf("%d\n", &... 阅读全文
posted @ 2018-03-22 00:43 cucy_to 阅读(149) 评论(0) 推荐(0)
摘要:```go package main import ( "encoding/json" "fmt" "time" ) func main() { eur, err := time.LoadLocation("Europe/Vienna") if err != nil { panic(err) } t 阅读全文
posted @ 2018-03-22 00:37 cucy_to 阅读(96) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "time" ) func main() { to := time.After(3 time.Second) list := make([]string, 0) done := make(chan bool, 1) fmt.Prin 阅读全文
posted @ 2018-03-22 00:36 cucy_to 阅读(109) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "sync" "time" ) func main() { t := time.NewTimer(3 time.Second) fmt.Printf("Start waiting at %v\n", time.Now().Forma 阅读全文
posted @ 2018-03-22 00:35 cucy_to 阅读(117) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "os" "os/signal" "time" ) func main() { c := make(chan os.Signal, 1) signal.Notify(c) ticker := time.NewTicker(time. 阅读全文
posted @ 2018-03-22 00:32 cucy_to 阅读(118) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "time" ) func main() { eur, err := time.LoadLocation("Europe/Vienna") if err != nil { panic(err) } t := time.Date(2000, 1, 1, 0, 0, 0, 0, eur) fmt.Printf... 阅读全文
posted @ 2018-03-22 00:31 cucy_to 阅读(99) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "time" ) func main() { l, err := time.LoadLocation("Asia/Shanghai") if err != nil { panic(err) } t := time.Date(2000, 1, 1, 0, 0, 0, 0, l) t2 := time.Da... 阅读全文
posted @ 2018-03-22 00:30 cucy_to 阅读(89) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "time" ) func main() { l, err := time.LoadLocation("Asia/Shanghai") if err != nil { panic(err) } t := time.Date(2017, 11, 30, 11, 10, 20, 0, l) fmt.Print... 阅读全文
posted @ 2018-03-22 00:29 cucy_to 阅读(101) 评论(0) 推荐(0)