Skip to content

Instantly share code, notes, and snippets.

View hantuo's full-sized avatar
💭
I may be slow to respond.

韩拓 hantuo

💭
I may be slow to respond.
View GitHub Profile
@hantuo
hantuo / generic.md
Last active September 7, 2018 16:55
Generic as a kind of types -- type T generic {int, float64}

Generic function implementation:

/*

* "generic" is a KIND of types, just like "struct", "map", "interface", etc...
* "T" is a generic type (a type of kind generic).
* var t = T{int} is a value of type T, values of generic types looks like a "normal" type

*/
@hantuo
hantuo / main.go
Last active December 20, 2016 17:31
untyped json unmarshal
package main
import "encoding/json"
import "fmt"
import "strconv"
import "reflect"
var A = `[1, "2"]`
var B = `[3, 4]`
var C = `[5, {"a":"b"}]`
=========================客户端
package main
import "net/http"
func main() {
req, _ := http.NewRequest("GET", "http://localhost:12346/aaa", nil)
req.Header.Set("User-Agent", "abc")
http.DefaultClient.Do(req)
@hantuo
hantuo / gist:3073832
Created July 9, 2012 02:07
golang dynamic type
package main
type I interface {
Foo()
}
type A struct {
}
package main
import (
"fmt"
)
func merge(a, b []int) (c []int) {
c = make([]int, len(a)+len(b))
var i, j, k int
fmt.Println("a: ", a)