@@ -17,7 +17,7 @@ func main() {
|
||||
// Go supports both standard and URL-compatible
|
||||
// base64. Here's how to encode using the standard
|
||||
// encoder. The encoder requires a `[]byte` so we
|
||||
// cast our `string` to that type.
|
||||
// convert our `string` to that type.
|
||||
sEnc := b64.StdEncoding.EncodeToString([]byte(data))
|
||||
fmt.Println(sEnc)
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
e57f5be3a796261fb4a55cdb0580a254e14b4930
|
||||
t6rFm2x4Yr
|
||||
c20da14820b656c867790f2e99bc37140babca8c
|
||||
y_QTcqdkvZh
|
||||
|
||||
@@ -22,7 +22,7 @@ func main() {
|
||||
fmt.Println(d)
|
||||
|
||||
// A numeric constant has no type until it's given
|
||||
// one, such as by an explicit cast.
|
||||
// one, such as by an explicit conversion.
|
||||
fmt.Println(int64(d))
|
||||
|
||||
// A number can be given a type by using it in a
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
3de4f16f1ed032378268411b2173b95e8000305d
|
||||
T5sj0eINnp
|
||||
2f2ec3a5ff4eef280199da1908eed261346fb40e
|
||||
VhP0f8moZd3
|
||||
|
||||
@@ -85,14 +85,14 @@ func main() {
|
||||
fmt.Println(dat)
|
||||
|
||||
// In order to use the values in the decoded map,
|
||||
// we'll need to cast them to their appropriate type.
|
||||
// For example here we cast the value in `num` to
|
||||
// we'll need to convert them to their appropriate type.
|
||||
// For example here we convert the value in `num` to
|
||||
// the expected `float64` type.
|
||||
num := dat["num"].(float64)
|
||||
fmt.Println(num)
|
||||
|
||||
// Accessing nested data requires a series of
|
||||
// casts.
|
||||
// conversions.
|
||||
strs := dat["strs"].([]interface{})
|
||||
str1 := strs[0].(string)
|
||||
fmt.Println(str1)
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
43e8d66fb862ea224994ca766e5689a96016f7ca
|
||||
UGeNKd-cw34
|
||||
d4dc2281f64061f077d8f1e9687538f41a339b25
|
||||
xC6SHbzGBZC
|
||||
|
||||
@@ -33,8 +33,8 @@ func (s byLength) Less(i, j int) bool {
|
||||
}
|
||||
|
||||
// With all of this in place, we can now implement our
|
||||
// custom sort by casting the original `fruits` slice to
|
||||
// `byLength`, and then use `sort.Sort` on that typed
|
||||
// custom sort by converting the original `fruits` slice
|
||||
// to `byLength`, and then use `sort.Sort` on that typed
|
||||
// slice.
|
||||
func main() {
|
||||
fruits := []string{"peach", "banana", "kiwi"}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
a5bcb1620c62f89f8253d7d2a2580b5ae48771b6
|
||||
4b7_qiGp33y
|
||||
6a04058b564d5741815e523f97f240ee6563cb15
|
||||
y3kuCwIFRYK
|
||||
|
||||
Reference in New Issue
Block a user