base code update

This commit is contained in:
Sense T
2024-04-07 10:08:02 +08:00
parent 0a20b5a670
commit d90e949472
6 changed files with 55 additions and 77 deletions

View File

@@ -5,13 +5,11 @@ import (
"reCoreD-UI/models"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
func (s *Server) getDomains(c *gin.Context) {
domains, err := s.controller.GetDomains("")
if err != nil {
logrus.Error(err)
errorHandler(c, err)
return
}

View File

@@ -4,6 +4,7 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
type Response struct {
@@ -13,6 +14,7 @@ type Response struct {
}
func errorHandler(c *gin.Context, err error) {
logrus.Error(err)
c.JSON(http.StatusInternalServerError, Response{
Succeed: false,
Message: err.Error(),

35
server/static.go Normal file
View File

@@ -0,0 +1,35 @@
package server
import (
"embed"
"io/fs"
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
//go:generate cp -r ../web/dist ./
//go:embed dist
var staticFiles embed.FS
func staticFileHandler() gin.HandlerFunc {
sf, err := fs.Sub(staticFiles, "dist")
if err != nil {
logrus.Fatal("compile error: ", err)
}
fs := http.FileServer(http.FS(sf))
return func(ctx *gin.Context) {
defer ctx.Abort()
filename := strings.TrimLeft(ctx.Request.RequestURI, "/")
if filename == "" {
filename = "index.html"
}
fs.ServeHTTP(ctx.Writer, ctx.Request)
}
}