personal-website/main.go

140 lines
3.7 KiB
Go
Raw Normal View History

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-04-14 15:53:23 +00:00
"personalwebsite/websiteapp/blogviewer"
2023-03-20 11:20:37 +00:00
"personalwebsite/websiteapp/finder"
2023-04-12 21:05:23 +00:00
imgviewer "personalwebsite/websiteapp/img-viewer"
2023-03-17 01:16:51 +00:00
"personalwebsite/websiteapp/personalprops"
2023-03-15 00:05:24 +00:00
"github.com/gin-gonic/gin"
)
func main() {
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-04-12 21:05:23 +00:00
imgViewerApp := imgviewer.NewImgViewerApp()
2023-04-14 15:53:23 +00:00
blogViewerApp := blogviewer.NewBlogViewerApp()
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-04-12 21:05:23 +00:00
appsStorage.Apps["img-viewer"] = &imgViewerApp
2023-04-14 15:53:23 +00:00
appsStorage.Apps["blog-viewer"] = blogViewerApp
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-15 12:32:41 +00:00
}
2023-03-17 01:16:51 +00:00
app := router.Group("application")
{
persPropApp := app.Group("personal-properties")
{
2023-03-18 00:34:56 +00:00
persPropApp.GET("render", func(ctx *gin.Context) {
2023-04-13 01:09:07 +00:00
isMobileParam := ctx.Query("isMobile")
isMobile := isMobileParam == "true"
if isMobile {
ctx.HTML(http.StatusOK, "personal-properties/mobile-app.tmpl", persPropsApp.Render())
} else {
ctx.HTML(http.StatusOK, "personal-properties/app.tmpl", persPropsApp.Render())
}
2023-03-17 01:16:51 +00:00
})
}
2023-03-22 18:00:04 +00:00
finderAppRoute := app.Group("finder")
{
finderAppRoute.GET("render", func(ctx *gin.Context) {
2023-04-13 01:09:07 +00:00
isMobileParam := ctx.Query("isMobile")
isMobile := isMobileParam == "true"
if isMobile {
ctx.HTML(http.StatusOK, "finder/mobile-app.tmpl", finderApp.Render(isMobile))
} else {
ctx.HTML(http.StatusOK, "finder/app.tmpl", finderApp.Render(isMobile))
}
})
finderAppRoute.GET("renderMobileDesktop", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "finder/mobile-desktop.tmpl", gin.H{})
2023-03-22 18:00:04 +00:00
})
}
2023-04-12 21:05:23 +00:00
imgViewerRoute := app.Group("img-viewer")
{
imgViewerRoute.GET("render", func(ctx *gin.Context) {
2023-04-13 01:09:07 +00:00
isMobileParam := ctx.Query("isMobile")
isMobile := isMobileParam == "true"
if isMobile {
ctx.HTML(http.StatusOK, "img-viewer/mobile-app.tmpl", imgViewerApp.Render(isMobile))
} else {
ctx.HTML(http.StatusOK, "img-viewer/app.tmpl", imgViewerApp.Render(isMobile))
}
2023-04-12 21:05:23 +00:00
})
}
2023-04-14 15:53:23 +00:00
blogViewerRoute := app.Group("blog-viewer")
{
blogViewerRoute.GET("render", func(ctx *gin.Context) {
isMobileParam := ctx.Query("isMobile")
isMobile := isMobileParam == "true"
if isMobile {
ctx.HTML(http.StatusOK, "blog-viewer/mobile-app.tmpl", blogViewerApp.Render(isMobile))
} else {
ctx.HTML(http.StatusOK, "blog-viewer/app.tmpl", blogViewerApp.Render(isMobile))
}
})
}
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
if err := router.Run(":8080"); err != nil {
log.Panicf("error: %s", err)
}
}
func index(c *gin.Context) {
c.HTML(http.StatusOK, "base.html", nil)
}