-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
57 lines (48 loc) · 1.12 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
package main
import (
"embed"
"log"
"os"
"time"
"github.com/tech-thinker/linkly/api/routes"
"github.com/gin-gonic/gin"
)
// @title Linkly API
// @version 1.0
// @description URL shortener API
// @termsOfService /terms/
// @contact.name API Support
// @contact.url /support
// @contact.email
// @license.name MIT License
// @license.url https://github.com/tech-thinker/linkly/blob/main/LICENSE
// @host localhost:8080
// @BasePath /
// @schemes http https
// @securityDefinitions.basic BasicAuth
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
//go:embed views/*
var viewsFs embed.FS
var (
// startTime is the time when the server starts
startTime time.Time = time.Now()
)
func main() {
// Get port from env
port := ":3000"
_, present := os.LookupEnv("PORT")
if present {
port = ":" + os.Getenv("PORT")
}
// Set the router as the default one shipped with Gin
server := gin.Default()
// Initialize the routes
routes.StartTime = startTime
routes.ViewsFs = viewsFs
routes.InitRoutes(server)
routes.BootTime = time.Since(startTime)
// Start and run the server
log.Fatal(server.Run(port))
}