-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
72 lines (53 loc) · 1.49 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
package main
import (
"errors"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/joho/godotenv"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
type Error struct {
Message string
}
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
err := godotenv.Load(".env.development")
if err != nil {
log.Fatal().Msg("Error loading enviroment variables")
log.Info().Msg("Error loading enviroment variables")
}
port, existPort := os.LookupEnv("PORT")
host, existHost := os.LookupEnv("HOST")
if !existPort || !existHost {
log.Fatal().Msg("Port or Host not set in environment variable")
log.Error().Err(errors.New("Port or Host not set in environment variable")).Msg("")
}
log.Info().Msg(port)
if err != nil {
log.Fatal().Msg(err.Error())
}
app := fiber.New()
app.Static("/logo/", "./public")
app.Use(cors.New())
app.Get("/hello", func(c *fiber.Ctx) error {
greeting := SayHello("Uchenna" + host)
return c.JSON(greeting)
})
app.Get("/banks", func(c *fiber.Ctx) error {
banks := getBanks(host)
return c.Status(fiber.StatusOK).JSON(banks)
})
app.Get("/schools", func(c *fiber.Ctx) error {
schools := getSchools(host)
return c.Status(fiber.StatusOK).JSON(schools)
})
// app.Use(logger.New(logger.Config{ // add Logger middleware with config
// Format: "[${ip}]:${port} ${status} - ${method} ${path}\n",
// }))
if err := app.Listen(":" + port); err != nil {
log.Info().Msg(host)
log.Log().Err(err)
}
}