|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + //"strconv" |
| 6 | + //"net" |
| 7 | + //"reflect" |
| 8 | + //"strings" |
| 9 | + //"syscall" |
| 10 | + //"unicode/utf16" |
| 11 | + "tcp_socket" |
| 12 | + "strings" |
| 13 | +) |
| 14 | + |
| 15 | +/*func in(ch chan string, s string) { |
| 16 | + for { |
| 17 | + ch <- "Counting" + s |
| 18 | + } |
| 19 | +}*/ |
| 20 | +var IsSystemDLL = map[string]bool{} |
| 21 | + |
| 22 | +func Add(dll string) string { |
| 23 | + IsSystemDLL[dll] = true |
| 24 | + return dll |
| 25 | +} |
| 26 | + |
| 27 | +type Base struct { |
| 28 | + name string |
| 29 | + age int |
| 30 | +} |
| 31 | + |
| 32 | +func (base *Base) Foo() { |
| 33 | + fmt.Println("Base Foo func call", base.name) |
| 34 | + base.name = "haha" |
| 35 | +} |
| 36 | +func (base *Base) Bar() { |
| 37 | + fmt.Println("Base Bar func call", base.age) |
| 38 | +} |
| 39 | + |
| 40 | +type Foo struct { |
| 41 | + name string |
| 42 | + Base |
| 43 | +} |
| 44 | + |
| 45 | +const big = 0xFFFFFF |
| 46 | + |
| 47 | +// Decimal to integer. |
| 48 | +// Returns number, characters consumed, success. |
| 49 | +func dtoi(s string) (n int, i int, ok bool) { |
| 50 | + n = 0 |
| 51 | + for i = 0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ { |
| 52 | + fmt.Println(s[i]) |
| 53 | + n = n*10 + int(s[i]-'0') |
| 54 | + if n >= big { |
| 55 | + return big, i, false |
| 56 | + } |
| 57 | + } |
| 58 | + if i == 0 { |
| 59 | + return 0, 0, false |
| 60 | + } |
| 61 | + return n, i, true |
| 62 | +} |
| 63 | + |
| 64 | +type t_int struct{ int } |
| 65 | + |
| 66 | +var v_string = "123" |
| 67 | +var index = strings.IndexByte(v_string, '2') |
| 68 | + |
| 69 | +var dateLayouts []string |
| 70 | + |
| 71 | +func init_1() { |
| 72 | + // Generate layouts based on RFC 5322, section 3.3. |
| 73 | + |
| 74 | + dows := [...]string{"", "Mon, "} // day-of-week |
| 75 | + days := [...]string{"2", "02"} // day = 1*2DIGIT |
| 76 | + years := [...]string{"2006", "06"} // year = 4*DIGIT / 2*DIGIT |
| 77 | + seconds := [...]string{":05", ""} // second |
| 78 | + // "-0700 (MST)" is not in RFC 5322, but is common. |
| 79 | + zones := [...]string{"-0700", "MST", "-0700 (MST)"} // zone = (("+" / "-") 4DIGIT) / "GMT" / ... |
| 80 | + |
| 81 | + for _, dow := range dows { |
| 82 | + for _, day := range days { |
| 83 | + for _, year := range years { |
| 84 | + for _, second := range seconds { |
| 85 | + for _, zone := range zones { |
| 86 | + s := dow + day + " Jan " + year + " 15:04" + second + " " + zone |
| 87 | + dateLayouts = append(dateLayouts, s) |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +func main() { |
| 96 | + tcp_socket.TCPServer() |
| 97 | + //chs := make(chan string) |
| 98 | + //for i := 0; i < 10; i++ { |
| 99 | + // go in(chs, strconv.Itoa(i)) |
| 100 | + //} |
| 101 | + //for { |
| 102 | + // fmt.Println(<-chs) |
| 103 | + //} |
| 104 | + /*var base1 Base = Base{"Job", 30} |
| 105 | + base1.Foo() |
| 106 | + base := Base{"huo", 20} |
| 107 | + foo := Foo{"AZaz", Base{"liu", 30}} |
| 108 | + base.Foo() |
| 109 | + foo.Foo() |
| 110 | + fmt.Println(base.name) |
| 111 | + fmt.Println(foo.name) |
| 112 | + fmt.Println(foo.Base.name) |
| 113 | + fmt.Println("hello world!") |
| 114 | + var domain string = "baidu.com" |
| 115 | + fmt.Println(net.LookupHost(domain)) |
| 116 | + v, _ := syscall.UTF16PtrFromString(domain) |
| 117 | + fmt.Println("UTF16", *v) |
| 118 | + var value interface{} |
| 119 | + value = *v |
| 120 | + switch t := (value).(type) { |
| 121 | + case string: |
| 122 | + fmt.Println("String", t) |
| 123 | + case int32: |
| 124 | + fmt.Println("INT32") |
| 125 | + case uint16: |
| 126 | + fmt.Println("uint16", t) |
| 127 | + default: |
| 128 | + fmt.Println("----") |
| 129 | + } |
| 130 | + for _, char := range []rune(domain) { |
| 131 | + fmt.Println(char) |
| 132 | + } |
| 133 | + a, _ := syscall.UTF16FromString(domain) |
| 134 | + fmt.Println(a) |
| 135 | + b := utf16.Encode([]rune(domain)) |
| 136 | + fmt.Println(b) |
| 137 | + c := utf16.Decode(b) |
| 138 | + fmt.Println(c) |
| 139 | + fmt.Println(syscall.UTF16ToString(b)) |
| 140 | + dll := Add("ws2_32.dll") |
| 141 | + fmt.Println(dll) |
| 142 | + dll1 := Add("ws2_32.dll") |
| 143 | + fmt.Println(dll1) |
| 144 | + fmt.Println(IsSystemDLL) |
| 145 | + //tcp_socket.TCPServer() |
| 146 | + type emptyCtx int |
| 147 | + background := new(emptyCtx) |
| 148 | + fmt.Println(background, *background) |
| 149 | + n, i, err := dtoi("udp") |
| 150 | + fmt.Println(n, i, err) |
| 151 | + by := '0' |
| 152 | + s1 := "101" |
| 153 | + fmt.Println(by) |
| 154 | + fmt.Println(int(s1[0] - '0')) |
| 155 | +
|
| 156 | + fmt.Println("-------") |
| 157 | + ch := make(chan int) |
| 158 | + go func() { |
| 159 | + for i := 0; i < 10; i = i + 1 { |
| 160 | + ch <- i |
| 161 | + } |
| 162 | + close(ch) |
| 163 | + }() |
| 164 | + for i := range ch { |
| 165 | + fmt.Println(i) |
| 166 | + } |
| 167 | + fmt.Println(net.DefaultResolver) |
| 168 | +
|
| 169 | + var v_int = 1 |
| 170 | + var p_v = &v_int |
| 171 | + var pp_v *int = &v_int |
| 172 | + var v_int1 = &t_int{} |
| 173 | + fmt.Println(p_v, pp_v) |
| 174 | + fmt.Println("type p_v:", reflect.TypeOf(p_v)) |
| 175 | + fmt.Println("type net.DefaultResolver:", reflect.TypeOf(net.DefaultResolver)) |
| 176 | + fmt.Println("type v_int1:", reflect.TypeOf(v_int1)) |
| 177 | + fmt.Println(v_int1) |
| 178 | + fmt.Println(index) |
| 179 | + fmt.Println(v_string[:index+1]) |
| 180 | + const ( |
| 181 | + max = uint32(1<<32 - 1) |
| 182 | + cutoff = uint32(1 << 30) |
| 183 | + ) |
| 184 | + fmt.Println(max) |
| 185 | + fmt.Println(cutoff) |
| 186 | + init_1() |
| 187 | + for v := range dateLayouts { |
| 188 | + fmt.Println(dateLayouts[v]) |
| 189 | + }*/ |
| 190 | + |
| 191 | +} |
0 commit comments