personal-website/main.go

116 lines
2.8 KiB
Go
Raw Normal View History

2023-03-15 00:05:24 +00:00
package main
import (
"log"
"net/http"
2023-03-15 12:32:41 +00:00
personalpropsroute "personalwebsite/approutes/personalPropsRoute"
2023-03-17 01:16:51 +00:00
"personalwebsite/routewde"
"personalwebsite/websiteapp"
"personalwebsite/websiteapp/personalprops"
2023-03-15 00:05:24 +00:00
"github.com/gin-gonic/gin"
)
2023-03-17 16:13:41 +00:00
// func main() {
// router := gin.Default()
// router.LoadHTMLGlob("templates/**/*")
// router.GET("/posts/index", func(c *gin.Context) {
// c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{
// "title": "Posts",
// })
// })
// router.GET("/users/index", func(c *gin.Context) {
// c.HTML(http.StatusOK, "users/index.tmpl", gin.H{
// "title": "Users",
// })
// })
// router.Run(":8080")
// }
2023-03-15 00:05:24 +00:00
func main() {
2023-03-17 16:13:41 +00:00
// hostUrl := "http://localhost:8080/"
2023-03-15 00:05:24 +00:00
router := gin.New()
// router.Use(rateLimit, gin.Recovery())
2023-03-17 16:13:41 +00:00
router.LoadHTMLGlob("templates/**/*")
2023-03-15 00:05:24 +00:00
// router.Static("/static", "resources/static")
router.Static("/res", "resources")
router.GET("/", index)
router.GET("/getmockapp", func(ctx *gin.Context) {
2023-03-15 12:32:41 +00:00
2023-03-15 00:05:24 +00:00
})
2023-03-17 01:16:51 +00:00
persPropsApp := personalprops.NewPersPropsApp()
appsStorage := websiteapp.ApplicationsStorage{
Apps: map[string]websiteapp.WebDEApplication{},
}
appsStorage.Apps["personal-properties"] = &persPropsApp
system := router.Group("system")
2023-03-15 12:32:41 +00:00
{
2023-03-17 01:16:51 +00:00
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":
2023-03-17 16:13:41 +00:00
ctx.HTML(http.StatusOK, "resources/"+appId+"/"+appId+".tmpl", nil)
2023-03-17 01:16:51 +00:00
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)
2023-03-15 12:32:41 +00:00
personalpropsroute.Route(apps.Group("/personalproperties"))
}
2023-03-17 01:16:51 +00:00
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) {
2023-03-17 16:13:41 +00:00
ctx.HTML(http.StatusOK, "personal-properties/app.tmpl", persPropsApp.Render())
2023-03-17 01:16:51 +00:00
})
}
}
2023-03-17 16:13:41 +00:00
router.GET("/test", func(ctx *gin.Context) {
ctx.HTML(200, "kek/kek.tmpl", gin.H{})
})
2023-03-15 00:05:24 +00:00
// 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)
}