摘要: ```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 阅读(299) 评论(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 阅读(116) 评论(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)
摘要: ```go package main import ( "fmt" "time" ) func main() { t := time.Date(2017, 11, 29, 21, 0, 0, 0, time.Local) fmt.Printf("Extracting units from: %v\n", t) dOfMonth := t.Day() weekDay := t.W... 阅读全文
posted @ 2018-03-22 00:27 cucy_to 阅读(149) 评论(0) 推荐(0)
摘要: ```go package main import ( "fmt" "time" ) func main() { // Set the epoch from int64 t := time.Unix(0, 0) fmt.Println(t) // Get the epoch // from Time instance epoch := t.Unix() fmt.Prin... 阅读全文
posted @ 2018-03-22 00:26 cucy_to 阅读(852) 评论(0) 推荐(0)
摘要: ```go package main import ( "fmt" "time" ) func main() { // If timezone is not defined // than Parse function returns // the time in UTC timezone. t, err := time.Parse("2/1/2006", "31/7/2015... 阅读全文
posted @ 2018-03-22 00:23 cucy_to 阅读(191) 评论(0) 推荐(0)
摘要: ```go package main import ( "fmt" "time" ) func main() { tTime := time.Date(2017, time.March, 5, 8, 5, 2, 0, time.Local) // The formatting is done // with use of reference value // Jan 2 15:... 阅读全文
posted @ 2018-03-22 00:21 cucy_to 阅读(119) 评论(0) 推荐(0)
摘要: ```go package main import ( "fmt" "time" ) func main() { today := time.Now() fmt.Println(today) } /* 2018-03-22 00:18:44.558974 +0800 CST m=+0.000385597 */ ``` 阅读全文
posted @ 2018-03-22 00:20 cucy_to 阅读(111) 评论(0) 推荐(0)
摘要: ```go package main import ( "crypto/md5" "fmt" "io" "os" ) var content = "This is content to check" func main() { checksum := MD5(content) checksum2 := FileMD5("content.dat") fmt.Printf("C... 阅读全文
posted @ 2018-03-22 00:19 cucy_to 阅读(203) 评论(0) 推荐(0)
摘要: ```go package main import ( "fmt" "math/cmplx" ) func main() { // complex numbers are // defined as real and imaginary // part defined by float64 a := complex(2, 3) fmt.Printf("Real part: ... 阅读全文
posted @ 2018-03-22 00:14 cucy_to 阅读(130) 评论(0) 推荐(0)
摘要: ```go package main import ( crypto "crypto/rand" "fmt" "math/big" "math/rand" ) func main() { sec1 := rand.New(rand.NewSource(10)) sec2 := rand.New(ra 阅读全文
posted @ 2018-03-22 00:12 cucy_to 阅读(111) 评论(0) 推荐(0)
摘要: ```go package main import ( "fmt" "strconv" ) const bin = "10111" const hex = "1A" const oct = "12" const dec = "10" const floatNum = 16.123557 func main() { // Converts binary value into hex ... 阅读全文
posted @ 2018-03-22 00:08 cucy_to 阅读(312) 评论(0) 推荐(0)
摘要: ```go package main import ( "fmt" ) var integer int64 = 32500 var floatNum float64 = 22000.456 func main() { // Common way how to print the decimal // number fmt.Printf("%d \n", integer) // ... 阅读全文
posted @ 2018-03-22 00:07 cucy_to 阅读(193) 评论(0) 推荐(0)
摘要: ```go package main import ( "fmt" "math" "math/big" ) const PI = const diameter = 3.0 const precision = 400 func main() { pi, _ := new(big.Float).SetP 阅读全文
posted @ 2018-03-22 00:03 cucy_to 阅读(148) 评论(0) 推荐(0)
摘要: ```go package main import ( "fmt" "math" ) var valA float64 = 3.55554444 func main() { // Bad assumption on rounding // the number by casting it to // integer. intVal := int(valA) fmt.Print... 阅读全文
posted @ 2018-03-22 00:01 cucy_to 阅读(75) 评论(0) 推荐(0)