]> Zhao Yanbai Git Server - acecode.git/commitdiff
...
authorAceVest <zhaoyanbai@126.com>
Fri, 2 Jun 2017 13:11:00 +0000 (21:11 +0800)
committerAceVest <zhaoyanbai@126.com>
Fri, 2 Jun 2017 13:11:00 +0000 (21:11 +0800)
learn/doc/mbp_bash_profile
learn/go/SimpleSvr.go
learn/go/array.slice.map.go
learn/go/reflect.go [new file with mode: 0644]
learn/go/string.go

index a7f6dc975186466ffd6bc07b56faa0e36cd8d786..b3831e845a0f29a98401423ac90f10d775380840 100644 (file)
@@ -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'
index 6512f41844a8ca9905214ffa5e9849488740d30e..cda53f3739bfba82c5e2c7fa9edfac6b0a8c2f88 100644 (file)
 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)
        }
index cc8a8fd4e4598ed2a6aa20f9a43bf146352f3047..cf530c56fe576d30c0aec455cfca8c5cb72a56a6 100644 (file)
@@ -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 (file)
index 0000000..f64221b
--- /dev/null
@@ -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)
+}
index 15798f3c4ecb0f4bf114b55d8a05a2ca0379eb60..b8c07f43ca13f1eb16a1493138ff9da4a6403c8d 100644 (file)
@@ -77,4 +77,7 @@ func main() {
        if err == nil {
                fmt.Println("strconv Atoi: ", val)
        }
+
+
+       fmt.Printf("%q\n", "hello world")       # 输出字符串前后会带双引号
 }