Skip to content

Instantly share code, notes, and snippets.

@sunzhongwei
Created October 9, 2013 05:46
Show Gist options
  • Save sunzhongwei/6896747 to your computer and use it in GitHub Desktop.
Save sunzhongwei/6896747 to your computer and use it in GitHub Desktop.
Golang slice usage
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func fetch_web_page() {
rsp, _ := http.Get("http://www.sunzhongwei.com")
html, _ := ioutil.ReadAll(rsp.Body)
new_html := string(html)
fmt.Println(new_html)
}
func slice_usage() {
sl := []int{}
sl = append(sl, 1)
sl = append(sl, 56)
fmt.Println(sl)
sl2 := []string{}
sl2 = append(sl2, "zhongwei")
sl2 = append(sl2, "test")
sl2 = append(sl2, "1", "2", "3")
fmt.Println(sl2)
fmt.Println("capacity of sl2 is:", cap(sl2))
fmt.Println("length of sl2 is:", len(sl2))
}
func main() {
fmt.Println("Start ...")
slice_usage()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment