base code update
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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
35
server/static.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user