-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (34 loc) · 1.15 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
package main
import (
// "encoding/json"
"fmt"
"github.com/gofiber/fiber/v2"
)
const (
bind_address string = "0.0.0.0" // empty means all available interfaces, set '0.0.0.0' here just for explitic value
bind_port string = "8000"
address string = bind_address + ":" + bind_port
)
func main() {
app := fiber.New()
// TODO: update home page handler to return some static content ... wip
app.Get("/", func(c *fiber.Ctx) error {
c.Set("Content-type", "application/json")
return c.SendString(`{"msg":"Hello from Fiber"}`)
})
app.Get("/api/hello", func(c *fiber.Ctx) error {
// j, err := json.Marshal(items)
// if err != nil { return err }
// c.Set("Content-type", "application/json; charset=utf-8")
c.Set("Content-type", "application/json") // should be enough
// return c.Send(j)
return c.SendString(`{"Hello":"World"}`)
})
app.Get("/api/info", func(c *fiber.Ctx) error {
c.Set("Content-type", "application/json")
return c.SendString(`{"msg":"Hello from Fiber"}`)
})
// TODO: add other routes (maybe in its own source), handlers, etc ... wip
fmt.Printf("Server listening on 'http://%s' ...\n", address)
app.Listen(address)
}