-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (56 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
package main
import (
"fmt"
"log"
"os"
_ "pet_api/docs"
"pet_api/src/controllers"
"pet_api/src/database"
"pet_api/src/database/migration"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/swagger"
"github.com/joho/godotenv"
)
// @title HairyPets API
// @version 1.0
// @description This is a HairyPets API swagger
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:3000
// @BasePath /api/v1
// @securityDefinitions.apikey ApiKeyAuth
// @In header
// @Name Authorization
// @Description Enter Bearer {token}
func main() {
if err := godotenv.Load(".env"); err != nil {
log.Fatal("Could no load .env file")
}
database.InitDatabase()
migration.RunMigration()
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowCredentials: false,
}))
app.Get("/swagger/*", swagger.HandlerDefault)
apiRoute := app.Group("/api")
apiV1 := apiRoute.Group("/v1", func(c *fiber.Ctx) error {
c.Set("Version", "v1")
c.Set("Callback-Token", "some-token-here")
return c.Next()
})
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello World!")
})
controllers.AddControllers(apiV1)
port := os.Getenv("PORT")
err := app.Listen(fmt.Sprintf(":%v", port))
if err != nil {
log.Fatal(err.Error())
}
}