Skip to content

Commit 59c5082

Browse files
committed
x
1 parent cec67a2 commit 59c5082

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

main.go

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package main
22

3+
import (
4+
"context"
5+
"fmt"
6+
"net"
7+
"net/http"
8+
"sync/atomic"
9+
)
10+
311
//
412
//import (
513
// "log"
@@ -38,21 +46,47 @@ package main
3846
// http.Handle("/metrics", promhttp.Handler())
3947
// log.Fatal(http.ListenAndServe(":8080", nil))
4048
//}
41-
import (
42-
"fmt"
43-
"net/http"
44-
_ "net/http/pprof"
45-
"time"
46-
)
47-
4849
func main() {
50+
//go func() {
51+
// http.ListenAndServe(":8088", nil)
52+
//}()
53+
//for i := 0; i < 100; i++ {
54+
// time.Sleep(time.Second)
55+
// fmt.Println(":", i)
56+
//}
57+
//ch := make(chan string)
58+
//<-ch
59+
60+
var count int32 = 0
61+
server := &http.Server{
62+
Addr: ":4444",
63+
Handler: http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
64+
rw.Header().Set("Connection", "close")
65+
}),
66+
ConnContext: func(ctx context.Context, c net.Conn) context.Context {
67+
atomic.AddInt32(&count, 1)
68+
if c2 := ctx.Value("count"); c2 != nil {
69+
fmt.Printf("发现了遗留数据: %d\n", c2.(int32))
70+
}
71+
fmt.Printf("本次数据: %d\n", count)
72+
return context.WithValue(ctx, "count", count)
73+
},
74+
}
4975
go func() {
50-
http.ListenAndServe(":8088", nil)
76+
panic(server.ListenAndServe())
5177
}()
52-
for i := 0; i < 100; i++ {
53-
time.Sleep(time.Second)
54-
fmt.Println(":", i)
78+
79+
var err error
80+
81+
fmt.Println("第一次请求")
82+
_, err = http.Get("http://localhost:4444/")
83+
if err != nil {
84+
panic(err)
85+
}
86+
fmt.Println("\n第二次请求")
87+
88+
_, err = http.Get("http://localhost:4444/")
89+
if err != nil {
90+
panic(err)
5591
}
56-
ch := make(chan string)
57-
<-ch
5892
}

test/main_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package test
22

33
import (
44
"encoding/base64"
5+
"encoding/hex"
56
"fmt"
67
"math/big"
78
"testing"
@@ -353,7 +354,7 @@ func testxx() {
353354
//encodeString2 := base64.StdEncoding.EncodeToString([]byte(hex.EncodeToString(out2)))
354355
//fmt.Println(encodeString2)
355356

356-
input := []byte("23")
357+
input := []byte("18160ddd")
357358
//input, _ := hex.DecodeString("0000000000000000000000006356908ace09268130dee2b7de643314bbeb36830000000000000000000000000000000000000000000000000000000000000004")
358359
// 演示base64编码
359360
encodeString := base64.StdEncoding.EncodeToString(input)
@@ -397,13 +398,16 @@ func testdefer() {
397398
fmt.Println("testdefer")
398399
}
399400
func TestXx(t *testing.T) {
400-
testdefer()
401+
//testdefer()
401402
//testyy()
402403
//testDijkstra()
403404
//testopenfile()
404405
//testudp()
405406
//testbroard()
406407
testxx()
408+
te := []byte{1, 2, 3}
409+
fmt.Println(fmt.Sprintf("%x", te))
410+
fmt.Println(hex.EncodeToString(te))
407411
//tag := []byte("123")
408412
//key := []byte("456")
409413
//k := make([]byte, len(tag)+len(key))

0 commit comments

Comments
 (0)