2023-03-15 00:05:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2023-03-17 01:16:51 +00:00
|
|
|
"personalwebsite/routewde"
|
|
|
|
"personalwebsite/websiteapp"
|
2023-03-20 11:20:37 +00:00
|
|
|
"personalwebsite/websiteapp/finder"
|
2023-03-17 01:16:51 +00:00
|
|
|
"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()
|
|
|
|
|
2023-03-18 00:34:56 +00:00
|
|
|
router.LoadHTMLGlob("templates/**/*")
|
2023-03-15 00:05:24 +00:00
|
|
|
router.Static("/res", "resources")
|
2023-03-15 12:32:41 +00:00
|
|
|
|
2023-03-18 00:34:56 +00:00
|
|
|
router.GET("/", func(ctx *gin.Context) {
|
|
|
|
ctx.HTML(http.StatusOK, "index.tmpl", gin.H{})
|
2023-03-15 00:05:24 +00:00
|
|
|
})
|
2023-03-18 00:34:56 +00:00
|
|
|
|
2023-03-17 01:16:51 +00:00
|
|
|
persPropsApp := personalprops.NewPersPropsApp()
|
2023-03-20 11:20:37 +00:00
|
|
|
finderApp := finder.FinerApplication{}
|
2023-03-17 01:16:51 +00:00
|
|
|
appsStorage := websiteapp.ApplicationsStorage{
|
|
|
|
Apps: map[string]websiteapp.WebDEApplication{},
|
|
|
|
}
|
|
|
|
appsStorage.Apps["personal-properties"] = &persPropsApp
|
2023-03-20 11:20:37 +00:00
|
|
|
appsStorage.Apps["finder"] = &finderApp
|
2023-03-17 01:16:51 +00:00
|
|
|
system := router.Group("system")
|
2023-03-15 12:32:41 +00:00
|
|
|
{
|
2023-03-18 00:34:56 +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 "app.js":
|
2023-03-20 11:20:37 +00:00
|
|
|
ctx.File("resources/sys/" + appId + "/" + appId + ".js")
|
2023-03-17 01:16:51 +00:00
|
|
|
case "app.css":
|
2023-03-20 11:20:37 +00:00
|
|
|
ctx.File("resources/sys/" + appId + "/" + appId + ".css")
|
2023-03-17 01:16:51 +00:00
|
|
|
default:
|
|
|
|
ctx.Status(http.StatusBadRequest)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
websiteapp.Route(apps.Group("/storage"), &appsStorage)
|
2023-03-20 11:20:37 +00:00
|
|
|
// personalpropsroute.Route(apps.Group("/personalproperties"))
|
2023-03-15 12:32:41 +00:00
|
|
|
}
|
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")
|
|
|
|
{
|
2023-03-18 00:34:56 +00:00
|
|
|
persPropApp.GET("render", 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)
|
|
|
|
}
|