/
main.go
80 lines (58 loc) · 1.3 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
package main
import (
"context"
"net/http"
"github.com/americanas-go/config"
logger "github.com/jvitoroc/ignite/americanas-go/log.v1"
"github.com/jvitoroc/ignite/gofiber/fiber.v2"
"github.com/jvitoroc/ignite/gofiber/fiber.v2/plugins/native/cors"
"github.com/jvitoroc/ignite/gofiber/fiber.v2/plugins/native/etag"
"github.com/americanas-go/log"
f "github.com/gofiber/fiber/v2"
)
const HelloWorldEndpoint = "app.endpoint.helloworld"
func init() {
config.Add(HelloWorldEndpoint, "/hello-world", "helloworld endpoint")
}
type Config struct {
App struct {
Endpoint struct {
Helloworld string
}
}
}
type Response struct {
Message string
}
type Handler struct {
}
func NewHandler() *Handler {
return &Handler{}
}
func (h *Handler) Get(c *f.Ctx) (err error) {
l := log.FromContext(context.Background())
resp := Response{
Message: "Hello World!!",
}
err = config.Unmarshal(&resp)
if err != nil {
l.Errorf(err.Error())
}
return c.Status(http.StatusOK).JSON(resp)
}
func main() {
config.Load()
c := Config{}
err := config.Unmarshal(&c)
if err != nil {
panic(err)
}
ctx := context.Background()
logger.New()
handler := &Handler{}
fiberSrv := fiber.NewServer(ctx,
cors.Register,
etag.Register)
fiberSrv.App().Get(c.App.Endpoint.Helloworld, handler.Get)
fiberSrv.Serve(ctx)
}