
golang
iteye_16277
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
go select
select用于处理多个ch。 其所有case中的channel表达式和右侧的发送语句都会被计算(从上到下) 如果多个case都可以执行,则随机选择一个case。 func test_select_recv() { ch := make(chan int) go func() { fmt.Println("select begin") select { ...原创 2014-01-17 16:41:56 · 137 阅读 · 0 评论 -
go misc
//有点没点不一样 days1 := [...]string{"Sat", "Sun"} //array [2]string days2 := []string{"Sat", "Sun"} //slice []string //key为位置 vowels := [...]bool{'a': true, 'e': true, 'i': true, 'o': true...原创 2014-01-17 16:59:21 · 142 阅读 · 0 评论 -
go json
import "encoding/json" type Message struct { Name string Body []string Time int64 tel string //not exported } m := Message{"jack", []string{"hello", "112"}, 1294706395881547000} r, e...原创 2014-01-17 22:51:31 · 98 阅读 · 0 评论 -
go xml
import ( "encoding/xml" "fmt" ) type Pkg struct { PkgType int `xml:"P"` //P:包类型 } type Message struct { XMLName xml.Name `xml:"DP"` Pkg Name string `xml:"D"` Age int //`xml...原创 2014-01-17 22:59:42 · 121 阅读 · 0 评论 -
go type switch
var v interface{} = "123" switch t := v.(type) { case nil: fmt.Println("v is nil") case int: fmt.Println("v is int") //fallthrough is not permitted in a type switch default: fmt....原创 2014-01-24 11:00:39 · 191 阅读 · 0 评论 -
go range
//array or slic datas := []int{1, 2, 3} //datas := [...]int{1, 2, 3} //datas := &[...]int{1, 2, 3} for idx, v := range datas { fmt.Println(idx, v) } //If only the first itera...原创 2014-01-24 13:13:10 · 105 阅读 · 0 评论 -
go built-in functions
close() len() cap() new() make() //slice, map, channel append() copy() delete() complex() real() imag() panic() recover() close(ch) //panic when ch is nil or closed channel len(ch)) ...原创 2014-01-24 14:05:52 · 156 阅读 · 0 评论 -
go 指针强转
import "unsafe" var a uint = 0 p := uintptr(unsafe.Pointer(&a)) for i := 0; i < int(unsafe.Sizeof(a)); i++ { p += 1 pb := (*byte)(unsafe.Pointer(p)) *pb = 1 } fmt.Printf...原创 2014-01-24 14:30:30 · 968 阅读 · 0 评论 -
go 反射
interface中保存了实际对象的值和类型 func TypeOf(i interface{}) Type func ValueOf(i interface{}) Value Settability is determined by whether the reflection object holds the original item var x float64 =...原创 2014-01-25 15:50:19 · 126 阅读 · 0 评论