增加日志输出
This commit is contained in:
parent
e2d8ab882b
commit
e1d0017257
|
@ -3,6 +3,7 @@ package async
|
||||||
import (
|
import (
|
||||||
"blog/third_party/database"
|
"blog/third_party/database"
|
||||||
"context"
|
"context"
|
||||||
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
@ -15,6 +16,7 @@ type ViewRecord struct {
|
||||||
ViewTime int64 `json:"viewTime"`
|
ViewTime int64 `json:"viewTime"`
|
||||||
IpAddr string `json:"ipAddr"`
|
IpAddr string `json:"ipAddr"`
|
||||||
RelId string `json:"relId"`
|
RelId string `json:"relId"`
|
||||||
|
Title string `json:"title" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -23,6 +25,7 @@ func init() {
|
||||||
go func() {
|
go func() {
|
||||||
|
|
||||||
for record := range viewRecordChannel {
|
for record := range viewRecordChannel {
|
||||||
|
log.Println("IP:", record.IpAddr, "点击了:", record.Title)
|
||||||
relId := record.RelId
|
relId := record.RelId
|
||||||
record.Id = uuid.NewString()
|
record.Id = uuid.NewString()
|
||||||
database.GormTemplate.Table("blog_view_record").Create(&record)
|
database.GormTemplate.Table("blog_view_record").Create(&record)
|
||||||
|
|
|
@ -53,7 +53,7 @@ func (ctrl *ArticleController) ViewArticle() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
xFrowardedFor := ctrl.Ctx.GetHeader("X-Forwarded-For")
|
xFrowardedFor := ctrl.Ctx.GetHeader("X-Forwarded-For")
|
||||||
async.PublishViewRecord(async.ViewRecord{RelId: articleId, IpAddr: xFrowardedFor, ViewTime: time.Now().UnixMilli()})
|
async.PublishViewRecord(async.ViewRecord{RelId: articleId, IpAddr: xFrowardedFor, ViewTime: time.Now().UnixMilli(), Title: article.Title})
|
||||||
|
|
||||||
content := service.ContentService.GetContentByCache(articleId)
|
content := service.ContentService.GetContentByCache(articleId)
|
||||||
ctrl.Ctx.ViewData("article", article)
|
ctrl.Ctx.ViewData("article", article)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"blog/internal/model/admin"
|
"blog/internal/model/admin"
|
||||||
"blog/third_party/database"
|
"blog/third_party/database"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kataras/iris/v12"
|
"github.com/kataras/iris/v12"
|
||||||
|
@ -92,5 +93,7 @@ func (ctrl *LoginController) Post() {
|
||||||
newSession.Set("user", user)
|
newSession.Set("user", user)
|
||||||
ctrl.Ctx.SetCookieKV("session_id_cookie", newSession.ID())
|
ctrl.Ctx.SetCookieKV("session_id_cookie", newSession.ID())
|
||||||
|
|
||||||
|
xFrowardedFor := ctrl.Ctx.GetHeader("X-Forwarded-For")
|
||||||
|
log.Println("用户:", user.Username, "登录,IP为:", xFrowardedFor)
|
||||||
ctrl.Ctx.JSON(AjaxResult.Ok("login"))
|
ctrl.Ctx.JSON(AjaxResult.Ok("login"))
|
||||||
}
|
}
|
||||||
|
|
2
main.go
2
main.go
|
@ -26,7 +26,6 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
profile := os.Getenv("profile")
|
profile := os.Getenv("profile")
|
||||||
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.LUTC | log.Llongfile)
|
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.LUTC | log.Llongfile)
|
||||||
log.Println("Go Iris 启动")
|
|
||||||
app := iris.Default()
|
app := iris.Default()
|
||||||
app.FallbackView(iris.FallbackView("404.html"))
|
app.FallbackView(iris.FallbackView("404.html"))
|
||||||
app.HandleDir("/assets", iris.Dir("./assets"))
|
app.HandleDir("/assets", iris.Dir("./assets"))
|
||||||
|
@ -43,6 +42,7 @@ func main() {
|
||||||
log.SetOutput(logFile)
|
log.SetOutput(logFile)
|
||||||
profile = "prod"
|
profile = "prod"
|
||||||
}
|
}
|
||||||
|
log.Println("Go Iris 启动")
|
||||||
log.Println("当前环境是:", profile)
|
log.Println("当前环境是:", profile)
|
||||||
|
|
||||||
app.OnErrorCode(http.StatusNotFound, func(ctx iris.Context) {
|
app.OnErrorCode(http.StatusNotFound, func(ctx iris.Context) {
|
||||||
|
|
Loading…
Reference in New Issue