This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fmt.Println("t1:", t1) | |
fmt.Println("t2:", t2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Time struct { | |
// ... (redacted) | |
// If the hasMonotonic bit is 1, then the 33-bit field holds a 33-bit | |
// unsigned wall seconds since Jan 1 year 1885, and ext holds a | |
// signed 64-bit monotonic clock reading, nanoseconds since process start. | |
wall uint64 | |
ext int64 | |
// loc specifies the Location that should be used to | |
// ... (redacted) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t1 := time.Now() | |
data, err := json.Marshal(t1) | |
if err != nil { | |
log.Fatal(err) | |
} | |
var t2 time.Time | |
if err := json.Unmarshal(data, &t2); err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(t1 == t2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"reflect" | |
"testing" | |
) | |
var ( | |
a1, b1 []int | |
aSize = 1239 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cart len: 3 cap: 3 | |
fruits len: 2 cap: 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fmt.Println("cart", "len:", len(cart), "cap:", cap(cart)) | |
fmt.Println("fruits", "len:", len(fruits), "cap:", cap(fruits)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cart := []string{"apple", "pear", "milk"} | |
fruits := cart[:2:2] | |
fruits = append(fruits, "lemon") | |
fmt.Println("cart:", cart, "fruits:", fruits) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cart len: 3 cap: 3 | |
fruits len: 2 cap: 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fmt.Println("cart", "len:", len(cart), "cap:", cap(cart)) | |
fmt.Println("fruits", "len:", len(fruits), "cap:", cap(fruits)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func appendInt(s []int, val int) []int { | |
idx := len(s) | |
if len(s) < cap(s) { | |
// Enough space, use same underlying array | |
s = s[:len(s)+1] | |
} else { | |
// Not enough space, allocate & copy | |
s1 := make([]int, 2*len(s)+1) | |
copy(s1, s) | |
s = s1[:len(s)+1] |