-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (62 loc) · 1.58 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
package main
import (
"runtime"
"github.com/gofiber/fiber"
"github.com/gofiber/limiter"
"github.com/jeffotoni/gokafka.poc/config"
hping "github.com/jeffotoni/gokafka.poc/controller/handler/ping"
htopic "github.com/jeffotoni/gokafka.poc/controller/handler/topic"
mw "github.com/jeffotoni/gokafka.poc/controller/middleware"
)
var (
conf = config.Config()
)
func init() {
if conf.Sys.NumCPU > 0 {
runtime.GOMAXPROCS(conf.Sys.NumCPU)
} else {
runtime.GOMAXPROCS(runtime.NumCPU())
}
// exec chec in
// system
config.Check()
}
var (
//Tamanho para todas as requisições
sizeBodyDefault = 3 * 1024 * 1024 //maximo para requests normais
sizeBodyProducer = 1 * 1024 * 1024 // maximo geral
)
func main() {
// app http
app := fiber.New()
// max body global
app.Settings.BodyLimit = sizeBodyDefault
//Rate Limite
app.Use(limiter.New(limiter.Config{
Timeout: 1,
Max: 100000,
Filter: nil,
StatusCode: 401,
Message: `{"msg":"Much Request #bloqued"}`,
}))
//==========================================
// middlewares
mw.Cors(app)
mw.Logger(app)
mw.Compress(app)
// GET ping -> pong
app.Get("/ping", hping.Ping)
// POST ping -> pong
app.Post("/ping", hping.Ping)
// handler create topic kafka-go
app.Post("/topic", htopic.Create)
// handler list all topics sarama
app.Get("/topic", htopic.ListAllTopics)
// handler delete topic sarama
app.Delete("/topic/:topic", htopic.Delete)
// middleware size producer
app.Use(mw.MaxBody(sizeBodyProducer))
// handler producer kafka-go
app.Post("/producer", htopic.Producer)
app.Listen(conf.Http.Port)
}