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
|
||||
|
||||
# Work dir and files
|
||||
*.log
|
||||
.idea
|
||||
tmp
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package mApp
|
||||
|
||||
import (
|
||||
"MollyBlog/config"
|
||||
"MollyBlog/internal/model"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
|
||||
"MollyBlog/config"
|
||||
"MollyBlog/internal/model"
|
||||
|
||||
"github.com/88250/lute"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/huichen/wukong/engine"
|
||||
@@ -40,11 +39,19 @@ const (
|
||||
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() {
|
||||
ma.loadRoutes()
|
||||
ma.loadTemplates()
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", ma.Host, ma.Port)
|
||||
log.Printf("mApp listening on %s\n", addr)
|
||||
err := ma.engine.Run(addr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -52,8 +59,8 @@ func (ma *MApp) Run() {
|
||||
}
|
||||
|
||||
func NewMApp(cfg *config.MConfig) *MApp {
|
||||
engine := gin.Default()
|
||||
engine.SetFuncMap(template.FuncMap{
|
||||
_engine := gin.Default()
|
||||
_engine.SetFuncMap(template.FuncMap{
|
||||
"add": func(a, b int) int {
|
||||
return a + b
|
||||
},
|
||||
@@ -76,7 +83,7 @@ func NewMApp(cfg *config.MConfig) *MApp {
|
||||
CategorizedPosts: make(map[string][]*model.MPost),
|
||||
|
||||
lute: lute.New(),
|
||||
engine: engine,
|
||||
engine: _engine,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,9 +3,9 @@ package mApp
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/huichen/wukong/types"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"MollyBlog/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/huichen/wukong/types"
|
||||
)
|
||||
|
||||
func (ma *MApp) IndexHandler(ctx *gin.Context) {
|
||||
@@ -407,12 +408,14 @@ func (ma *MApp) UpdateBlogHandler(ctx *gin.Context) {
|
||||
|
||||
err = ma.loadMarkdownFiles()
|
||||
if err != nil {
|
||||
log.Printf("load markdown files failed, err:%v\n", err)
|
||||
_ = ctx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = ma.parseMarkdowns()
|
||||
if err != nil {
|
||||
log.Printf("parse markdown files failed, err:%v\n", err)
|
||||
_ = ctx.Error(err)
|
||||
return
|
||||
}
|
||||
@@ -420,5 +423,6 @@ func (ma *MApp) UpdateBlogHandler(ctx *gin.Context) {
|
||||
// parse post index
|
||||
ma.loadPostIndex()
|
||||
|
||||
log.Println("update blog success")
|
||||
ctx.JSON(http.StatusOK, gin.H{"msg": "ok"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user