From: AceVest Date: Fri, 2 Jun 2017 13:11:00 +0000 (+0800) Subject: ... X-Git-Url: http://zhaoyanbai.com/repos/pkcs11-destroy.html?a=commitdiff_plain;h=cb655d9fb2fdb17d0f2c8435cc975480416fec90;p=acecode.git ... --- diff --git a/learn/doc/mbp_bash_profile b/learn/doc/mbp_bash_profile index a7f6dc9..b3831e8 100644 --- a/learn/doc/mbp_bash_profile +++ b/learn/doc/mbp_bash_profile @@ -9,7 +9,7 @@ export GOBIN=/Users/ace/.local/bin export PATH=/Users/ace/workspace/github/metasploit-framework:$PATH export MSF_DATABASE_CONFIG=/Users/ace/workspace/github/metasploit-framework/config/database.yml #多个GOPATH用';'分隔 go get会存到第一个目录 -export GOPATH=/Users/ace/go +export GOPATH=/Users/ace/workspace/go export PS1="\W\$ " alias ll='ls -lGh' alias ls='ls -Gh' diff --git a/learn/go/SimpleSvr.go b/learn/go/SimpleSvr.go index 6512f41..cda53f3 100644 --- a/learn/go/SimpleSvr.go +++ b/learn/go/SimpleSvr.go @@ -10,32 +10,34 @@ package main import ( - // "bufio" - // "fmt" + "bufio" + "fmt" "log" "net" ) func handleConn(conn net.Conn) { who := conn.RemoteAddr().String() - /* - input := bufio.NewScanner(conn) - for input.Scan() { - } - */ - //fmt.Println(who) log.Print(who + " connected to the server") + input := bufio.NewScanner(conn) + for input.Scan() { + fmt.Println(input.Text()) + } + + fmt.Println(who) + conn.Close() } func main() { defer log.Print("Program Exited...") log.Print("Program Started...") - - //listener, err := net.Listen("tcp", "localhost:6666") - listener, err := net.Listen("tcp", "10.135.190.233:6666") + log.Print(net.LookupHost("www.qq.com")) + return + listener, err := net.Listen("tcp", "localhost:6666") + //listener, err := net.Listen("tcp", "10.135.190.233:6666") if err != nil { log.Fatal(err) } diff --git a/learn/go/array.slice.map.go b/learn/go/array.slice.map.go index cc8a8fd..cf530c5 100644 --- a/learn/go/array.slice.map.go +++ b/learn/go/array.slice.map.go @@ -193,4 +193,14 @@ func AboutMap() { fmt.Printf("Version B: Value of items: %v (Invalid Method) \n", items) } + + var m1 map[string]int // 此时m1==nil + m1 = make(map[string]int) // 如果不为m1分配空间 + m1["test"] = 1 // 那么这一句会panic + + var m2 = make(map[string]int) + m2["test"] = 2 + + m3 := make(map[string]int) + m3["test"] = 3 } diff --git a/learn/go/reflect.go b/learn/go/reflect.go new file mode 100644 index 0000000..f64221b --- /dev/null +++ b/learn/go/reflect.go @@ -0,0 +1,47 @@ +/* + * ------------------------------------------------------------------------ + * File Name: reflect.go + * Author: Zhao Yanbai + * 2017-05-31 21:24:09 Wednesday CST + * Description: none + * ------------------------------------------------------------------------ + */ +package main +import ( + "fmt" + "reflect" +) + +func main() { + defer fmt.Println("Program Exited...") + + var a float32 = 6.18 + v := reflect.ValueOf(a) // Copy + + fmt.Printf("Type %s Value %v Value %f Value %s\n", reflect.TypeOf(a), v, v, v.String()) // reflect.ValueOf(a), reflect.ValueOf(a).String()) + + fmt.Println("Value: ", v) + fmt.Println("Type: ", v.Type()) + fmt.Println("Value Kind: ", v.Kind()) + fmt.Println("Value: ", v.Float()) + fmt.Println("Interface: ", v.Interface()) + + b := v.Interface().(float32) + fmt.Println(b) + + + // v.SetFloat(3.14) // panic: reflect: reflect.Value.SetFloat using unaddressable value + + fmt.Println("Settability of v:", v.CanSet()) + + + p := reflect.ValueOf(&a) + fmt.Println("Type of p:", p.Type()) + fmt.Println("Settability of p:", p.CanSet()) + fmt.Println("The Element Of p:", p.Elem()) + fmt.Println("Settability of p.Elem:", p.Elem().CanSet()) + p.Elem().SetFloat(3.14) + fmt.Println("p.Elem.Interface:", p.Elem().Interface()) + fmt.Println("p.Elem:", p.Elem()) + fmt.Println("a:", a) +} diff --git a/learn/go/string.go b/learn/go/string.go index 15798f3..b8c07f4 100644 --- a/learn/go/string.go +++ b/learn/go/string.go @@ -77,4 +77,7 @@ func main() { if err == nil { fmt.Println("strconv Atoi: ", val) } + + + fmt.Printf("%q\n", "hello world") # 输出字符串前后会带双引号 }