-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
81 lines (71 loc) · 1.84 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// main.go
package main
import (
"bytes"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/guzenok/api-benchmark/serv"
"github.com/pkg/profile"
)
var (
pprof = flag.String("pprof", "Mem", "Which profile use (CPU, Mem, Block, Trace or Mutex)")
httpserv = flag.String("httpserv", "Gin", "Which type of http-server use (Gin or Chi)")
parser = flag.String("parser", "Buger", "Which type of http-server use (Standart or Buger)")
)
func main() {
// разбор аргументов
flag.Parse()
// выбор профилировщика
pprofOpt, found := map[string]func(*profile.Profile){
"CPU": profile.CPUProfile,
"Mem": profile.MemProfile,
"Block": profile.BlockProfile,
"Mutex": profile.MutexProfile,
"Trace": profile.TraceProfile,
}[*pprof]
if !found {
flag.PrintDefaults()
return
}
defer profile.Start(profile.ProfilePath("."), pprofOpt).Stop()
// выбор http-обработчика
handleCreate, found := serv.HttpHandlerList[*httpserv]
if !found {
flag.PrintDefaults()
return
}
// выбор json-парсера
decodeFunc, found := serv.DecodesList[*parser]
if !found {
flag.PrintDefaults()
return
}
encodeFunc := serv.EncodesList[*parser]
// info
fmt.Printf("Start %s at http://localhost%s (parser %s)\n", *httpserv, serv.URL, *parser)
// OS Signal
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
// start http-server
stop := serv.HttpServe(serv.URL, handleCreate(decodeFunc, encodeFunc))
defer stop()
time.Sleep(time.Second) // пусть устаканится
// бесконечные запросы к серверу
data := serv.NewTransferRequest().ToJSON()
Infinity:
for {
select {
case <-sigs:
break Infinity
default:
break
}
body := bytes.NewReader(data)
serv.HttpGet(serv.URL, body)
time.Sleep(time.Millisecond)
}
}