-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (45 loc) · 1.09 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
package main
import (
"github.com/gofiber/fiber/v2"
)
type Food struct {
Name string `json:"name"`
Price int `json:"price"`
}
func main() {
app := fiber.New();
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("GET: Hello Fiber.");
})
app.Post("/", func(c *fiber.Ctx) error {
return c.SendString("POST: Hello Fiber.");
})
// Parameter and Parameter Optional.
app.Get("/hello/:name/:surname?", func(c *fiber.Ctx) error {
name := c.Params("name");
surname := c.Params("surname");
return c.SendString("Name: " + name + " " + surname);
})
// Query
app.Get("/hi", func(c *fiber.Ctx) error {
name := c.Query("name");
surname := c.Query("surname");
return c.SendString("Hi " + name + " " + surname);
})
// Query Parser
app.Get("/food", func(c *fiber.Ctx) error {
food := Food{};
c.QueryParser(&food);
return c.JSON(food);
})
// WildCard
app.Get("/wild/*", func(c *fiber.Ctx) error {
wildcard := c.Params("*");
return c.SendString(wildcard);
})
// Static File
app.Static("/web", "./ui", fiber.Static{
Index: "index.html",
})
app.Listen(":8009");
}