-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (52 loc) · 1.54 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
package main
import (
"fmt"
"github.com/endalk200/blazingly-fast-url-shortener/docs"
handler "github.com/endalk200/blazingly-fast-url-shortener/handler"
"github.com/endalk200/blazingly-fast-url-shortener/store"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)
// @title Blazingly Fast URL Shortener API
// @version 1.0
// @description Blazingly Fast URL Shortener API written in Go using Gin framework.
// @contact.name endalk200
// @contact.email eb808826@gmail.com
// @host localhost:9808
// @BasePath /
func main() {
gin.ForceConsoleColor()
r := gin.Default()
docs.SwaggerInfo.BasePath = "/"
// Root route for getting API information
// @summary Get API information
// @description Get API information
// @tags root
// @produce json
// @success 200 {object} string "Welcome to the URL Shortener API"
// @router / [get]
r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Welcome to the URL Shortener API",
})
})
r.POST("/urls", func(c *gin.Context) {
handler.CreateShortUrl(c)
})
r.GET("/urls", func(c *gin.Context) {
handler.GetShortUrls(c)
})
r.GET("/urls/:shortUrl", func(c *gin.Context) {
handler.GetUrlObj(c)
})
r.GET("/:shortUrl", func(c *gin.Context) {
handler.HandleShortUrlRedirect(c)
})
store.InitializeStore()
r.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
err := r.Run(":9808")
if err != nil {
panic(fmt.Sprintf("Failed to start the web server - Error: %v", err))
}
}