Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenhan wang
pastebin
Commits
b772f6d4
Commit
b772f6d4
authored
Dec 19, 2022
by
chenhan wang
Browse files
增加了IP和时间的日记记录
parent
28f2e8e9
Changes
5
Hide whitespace changes
Inline
Side-by-side
backend/__debug_bin.exe
0 → 100644
View file @
b772f6d4
File added
backend/app/controller/interface.go
View file @
b772f6d4
...
@@ -3,8 +3,8 @@ package controller
...
@@ -3,8 +3,8 @@ package controller
import
(
import
(
"net"
"net"
"net/http"
"net/http"
"
pastebin_
backend/app/response"
"backend/app/response"
//"pastebin_
backend/model"
"
backend/model"
//"error"
//"error"
"time"
"time"
...
...
backend/app/middleware/login.go
View file @
b772f6d4
...
@@ -2,33 +2,44 @@ package middleware
...
@@ -2,33 +2,44 @@ package middleware
import
(
import
(
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4"
//"time"
"log"
"os"
//"http/net"
//"http/net"
//"pastebin_backend/app/controller"
//"pastebin_backend/app/controller"
)
)
func
Auth
(
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
func
Auth
(
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
return
func
(
c
echo
.
Context
)
error
{
return
func
(
c
echo
.
Context
)
error
{
//c.Bind("User")
mylogger
(
c
)
/*
cookie, _ := c.Cookie("user")
if cookie == nil {
err := controller.AskPasswd(c)
if err != nil {
return nil
}
}*/
//c.Set("uid", cookie.Value)
c
.
Set
(
"uid"
,
114514
)
c
.
Set
(
"uid"
,
114514
)
return
next
(
c
)
return
next
(
c
)
}
}
}
}
type
logInfo
struct
{
User_Agent
string
IP
string
time
string
path
string
}
/*
/*
func CookieAuth(c echo.Context) error{
向文件或 stdout 输出详细的日志,记录用户的 User-Agent、IP 地址、访问时间、访问路径等信息
cookie, err := c.Cookie()
User-Agent,访问路径,暂且无法实现
*/
func
mylogger
(
c
echo
.
Context
)
{
//c.GET("User-Agent")
//userAgent := controller.Ctx.Request.Header.Get("User-Agent")
ip
:=
echo
.
ExtractIPDirect
()(
c
.
Request
())
//日志输出文件
file
,
err
:=
os
.
OpenFile
(
"backend/files/sys.log"
,
os
.
O_CREATE
|
os
.
O_WRONLY
|
os
.
O_APPEND
,
0666
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
log
.
Fatalln
(
"Faild to open error logger file:"
,
err
)
}
}
//自定义日志格式
}*/
Info
:=
log
.
New
(
file
,
"[Info]"
,
log
.
Llongfile
)
Info
.
SetFlags
(
log
.
Ldate
|
log
.
Ltime
)
Info
.
Println
(
ip
)
}
backend/go.mod
View file @
b772f6d4
...
@@ -4,7 +4,6 @@ go 1.19
...
@@ -4,7 +4,6 @@ go 1.19
require (
require (
github.com/go-playground/validator/v10 v10.11.1
github.com/go-playground/validator/v10 v10.11.1
github.com/google/uuid v1.1.2
github.com/labstack/echo/v4 v4.9.1
github.com/labstack/echo/v4 v4.9.1
github.com/sirupsen/logrus v1.9.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.14.0
github.com/spf13/viper v1.14.0
...
...
backend/go.sum
View file @
b772f6d4
...
@@ -123,7 +123,6 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe
...
@@ -123,7 +123,6 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment