-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (46 loc) · 1.38 KB
/
main.go
File metadata and controls
53 lines (46 loc) · 1.38 KB
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
package main
import (
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/swagger"
"github.com/gofiber/template/html"
_ "github.com/joho/godotenv/autoload"
"log"
"os"
_ "web-service/docs"
"web-service/handlers"
"web-service/handlers/spotify"
)
func middleware(c *fiber.Ctx) error {
fmt.Println("Run middleware here")
return c.Next()
}
// @title Fiber Example API
// @version 1.0
// @description This is a sample swagger for Fiber
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.email fiber@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:3000
// @BasePath /
func main() {
engine := html.New("./views", ".html")
app := fiber.New(fiber.Config{Views: engine})
app.Use(cors.New(cors.Config{AllowHeaders: "Origin, Content-Type, Accept"}))
app.Static("/static", "./public")
app.Get("/swagger/*", swagger.HandlerDefault)
app.Get("/", handlers.Index)
api := app.Group("/api", middleware)
spotify.AddSpotifyRoutes(api)
app.Post("/email", handlers.Email)
port, exists := os.LookupEnv("PORT")
if !exists {
port = "8080" // TODO: change port number in cloud run inline yaml or define yaml
}
fmt.Println("Starting app in development mode")
// Run the app as a typical Go Fiber app for development
log.Fatal(app.Listen(":" + port))
}