personal-website/main.go

97 lines
2.3 KiB
Go

package main
import (
"log"
"net/http"
personalpropsroute "personalwebsite/approutes/personalPropsRoute"
"personalwebsite/routewde"
"personalwebsite/websiteapp"
"personalwebsite/websiteapp/personalprops"
"github.com/gin-gonic/gin"
)
func main() {
// hostUrl := "http://192.168.88.10:8080/"
router := gin.New()
// router.Use(rateLimit, gin.Recovery())
router.LoadHTMLGlob("resources/*.html")
// router.Static("/static", "resources/static")
router.Static("/res", "resources")
router.GET("/", index)
router.GET("/getmockapp", func(ctx *gin.Context) {
})
persPropsApp := personalprops.NewPersPropsApp()
appsStorage := websiteapp.ApplicationsStorage{
Apps: map[string]websiteapp.WebDEApplication{},
}
appsStorage.Apps["personal-properties"] = &persPropsApp
system := router.Group("system")
{
wde := system.Group("wde")
{
routewde.Route(wde)
}
apps := system.Group("applications")
{
apps.GET("/:appid/:method", func(ctx *gin.Context) {
appId := ctx.Param("appid")
method := ctx.Param("method")
app, isExist := appsStorage.Apps[appId]
if !isExist {
ctx.Status(http.StatusNoContent)
return
}
switch method {
case "getmanifest":
ctx.JSON(http.StatusOK, app.GetManifest())
case "gethtml":
ctx.HTML(http.StatusOK, appId+".html", nil)
case "app.js":
ctx.File("resources/applications/" + appId + "/" + appId + ".js")
case "app.css":
ctx.File("resources/applications/" + appId + "/" + appId + ".css")
default:
ctx.Status(http.StatusBadRequest)
}
})
}
websiteapp.Route(apps.Group("/storage"), &appsStorage)
personalpropsroute.Route(apps.Group("/personalproperties"))
}
app := router.Group("application")
{
app.GET("test", func(ctx *gin.Context) {
ctx.Status(http.StatusOK)
})
persPropApp := app.Group("personal-properties")
{
persPropApp.GET("getcontent", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "personal-properties.html", persPropsApp.Render())
})
}
}
// router.GET("/room/:roomid", roomGET)
// router.POST("/room-post/:roomid", roomPOST)
// router.GET("/stream/:roomid", streamRoom)
// port := os.Getenv("PORT")
// if port == "" {
// port = "8080"
// }
if err := router.Run(":8080"); err != nil {
log.Panicf("error: %s", err)
}
}
func index(c *gin.Context) {
c.HTML(http.StatusOK, "base.html", nil)
}