随笔分类 -  golibs

摘要:```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 阅读(112) 评论(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)
摘要:```go package main import ( "fmt" "math" ) const da = 0.29999999999999998889776975374843459576368331909180 const db = 0.3 func main() { daStr := fmt.S 阅读全文
posted @ 2018-03-21 23:59 cucy_to 阅读(126) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "strconv" ) const bin = "00001" const hex = "2f" const intString = "12" const floatString = "12.3" func main() { // Decimals res, err := strconv.Atoi(intStrin... 阅读全文
posted @ 2018-03-21 23:56 cucy_to 阅读(289) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "strconv" "strings" "unicode" ) func main() { text := "Hi! Go is awesome." text = Indent(text, 6) fmt.Println(text) text = Unindent(text, 3) fmt.Println... 阅读全文
posted @ 2018-03-21 23:53 cucy_to 阅读(107) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "math" "regexp" "strconv" "strings" ) func main() { stringToTrim := "\t\t\n Go \tis\t Awesome \t\t" trimResult := strings.TrimSpace(stringToTrim) fmt.Pr... 阅读全文
posted @ 2018-03-21 23:52 cucy_to 阅读(141) 评论(0) 推荐(0)
摘要:data.csv un_comment.csv 阅读全文
posted @ 2018-03-21 23:50 cucy_to 阅读(102) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "strings" "unicode" ) const email = "ExamPle@domain.com" const name = "isaac newton" const upc = "upc" const i = "i" const snakeCase = "first_name" func main(... 阅读全文
posted @ 2018-03-21 23:44 cucy_to 阅读(139) 评论(0) 推荐(0)
摘要:cat /Users/zrd/Downloads/gostandardlib/Chapter02/Strings\ and\ Things/recipe08/win1250.txt Gda�sk% decode 阅读全文
posted @ 2018-03-21 23:43 cucy_to 阅读(84) 评论(0) 推荐(0)
摘要:```go package main import ( "fmt" "regexp" ) const refString = `[{ \"email\": \"email@example.com\" \"phone\": 555467890}, { \"email\": \"other@domain 阅读全文
posted @ 2018-03-21 23:24 cucy_to 阅读(104) 评论(0) 推荐(0)