-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (37 loc) · 967 Bytes
/
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
package main
import (
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
)
type userPost struct {
Name string `json:"name"`
Cpf string `json:"cpf"`
Year int `json:"year"`
}
func main() {
app := fiber.New(fiber.Config{
Concurrency: 262144,
BodyLimit: 1 * 1024 * 1024,
})
app.Use(logger.New(logger.Config{
Format: "${pid} ${time} ${method} ${path} - ${ip} - ${status} - ${latency}\n",
TimeFormat: "02-Jan-2006 15:04:05",
Output: os.Stdout,
}))
app.Get("/api/v1/ping", Ping)
app.Post("/api/v1/user", User)
app.Listen("0.0.0.0:8080")
}
func Ping(c *fiber.Ctx) error {
c.Set("Content-Type", "application/json")
return c.Status(200).SendString(`{"msg":"pong❤️"}`)
}
func User(c *fiber.Ctx) (err error) {
var user userPost
err = c.BodyParser(&user)
if err != nil {
return c.Status(400).SendString(`{"msg":"error parse, json:` + err.Error() + `"}`)
}
return c.Status(200).JSON(user)
}