mirror of
https://github.com/yv1ing/MollyBlog.git
synced 2025-09-16 14:53:45 +08:00
fix: Corrected log format
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
|
||||||
|
|
||||||
# Work dir and files
|
# Work dir and files
|
||||||
|
*.log
|
||||||
.idea
|
.idea
|
||||||
tmp
|
tmp
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package mApp
|
package mApp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"MollyBlog/config"
|
||||||
|
"MollyBlog/internal/model"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"MollyBlog/config"
|
|
||||||
"MollyBlog/internal/model"
|
|
||||||
|
|
||||||
"github.com/88250/lute"
|
"github.com/88250/lute"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/huichen/wukong/engine"
|
"github.com/huichen/wukong/engine"
|
||||||
@@ -40,11 +39,19 @@ const (
|
|||||||
DST = "_post/dst" // destination html files
|
DST = "_post/dst" // destination html files
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log.SetPrefix("[MollyBlog] ")
|
||||||
|
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||||
|
|
||||||
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
}
|
||||||
|
|
||||||
func (ma *MApp) Run() {
|
func (ma *MApp) Run() {
|
||||||
ma.loadRoutes()
|
ma.loadRoutes()
|
||||||
ma.loadTemplates()
|
ma.loadTemplates()
|
||||||
|
|
||||||
addr := fmt.Sprintf("%s:%d", ma.Host, ma.Port)
|
addr := fmt.Sprintf("%s:%d", ma.Host, ma.Port)
|
||||||
|
log.Printf("mApp listening on %s\n", addr)
|
||||||
err := ma.engine.Run(addr)
|
err := ma.engine.Run(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -52,8 +59,8 @@ func (ma *MApp) Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewMApp(cfg *config.MConfig) *MApp {
|
func NewMApp(cfg *config.MConfig) *MApp {
|
||||||
engine := gin.Default()
|
_engine := gin.Default()
|
||||||
engine.SetFuncMap(template.FuncMap{
|
_engine.SetFuncMap(template.FuncMap{
|
||||||
"add": func(a, b int) int {
|
"add": func(a, b int) int {
|
||||||
return a + b
|
return a + b
|
||||||
},
|
},
|
||||||
@@ -76,7 +83,7 @@ func NewMApp(cfg *config.MConfig) *MApp {
|
|||||||
CategorizedPosts: make(map[string][]*model.MPost),
|
CategorizedPosts: make(map[string][]*model.MPost),
|
||||||
|
|
||||||
lute: lute.New(),
|
lute: lute.New(),
|
||||||
engine: engine,
|
engine: _engine,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package mApp
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/huichen/wukong/types"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"MollyBlog/utils"
|
"MollyBlog/utils"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/huichen/wukong/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ma *MApp) IndexHandler(ctx *gin.Context) {
|
func (ma *MApp) IndexHandler(ctx *gin.Context) {
|
||||||
@@ -407,12 +408,14 @@ func (ma *MApp) UpdateBlogHandler(ctx *gin.Context) {
|
|||||||
|
|
||||||
err = ma.loadMarkdownFiles()
|
err = ma.loadMarkdownFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("load markdown files failed, err:%v\n", err)
|
||||||
_ = ctx.Error(err)
|
_ = ctx.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ma.parseMarkdowns()
|
err = ma.parseMarkdowns()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("parse markdown files failed, err:%v\n", err)
|
||||||
_ = ctx.Error(err)
|
_ = ctx.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -420,5 +423,6 @@ func (ma *MApp) UpdateBlogHandler(ctx *gin.Context) {
|
|||||||
// parse post index
|
// parse post index
|
||||||
ma.loadPostIndex()
|
ma.loadPostIndex()
|
||||||
|
|
||||||
|
log.Println("update blog success")
|
||||||
ctx.JSON(http.StatusOK, gin.H{"msg": "ok"})
|
ctx.JSON(http.StatusOK, gin.H{"msg": "ok"})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user