ShortDragon/internal/web/router.go

27 lines
515 B
Go
Raw Normal View History

2021-03-07 19:51:18 +00:00
package web
import (
2021-03-08 00:10:56 +00:00
"os"
2021-03-07 19:51:18 +00:00
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
// InitRouter starts the router
func InitRouter() {
router := gin.Default()
router.POST("/e/", encode)
router.GET("/r/:short", redirect)
router.GET("/d/:short", decode)
router.GET("/i/:short", info)
router.GET("/f/:short", getFile)
if viper.GetBool("UseSocket") {
router.RunUnix(viper.GetString("BindSocket"))
2021-03-08 00:10:56 +00:00
os.Chmod(viper.GetString("BindSocket"), 0775)
2021-03-07 19:51:18 +00:00
} else {
router.Run(viper.GetString("BindAddress"))
}
}