-
Notifications
You must be signed in to change notification settings - Fork 34
/
Log.go
44 lines (38 loc) · 1.09 KB
/
Log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package audits
import (
"github.com/TeaWeb/code/teadb/shared"
"time"
)
// 动作
type Action = string
const (
ActionLogin = "LOGIN" // 登录 {ip}
)
// 审计日志
type Log struct {
Id shared.ObjectId `bson:"_id" json:"id"` // 数据库存储的ID
Username string `bson:"username" json:"username"`
Action Action `bson:"action" json:"action"` // 类型
Description string `bson:"description" json:"description"` // 描述
Options map[string]string `bson:"options" json:"options"` // 选项
Timestamp int64 `bson:"timestamp" json:"timestamp"` // 时间戳
}
// 获取新审计日志对象
func NewLog(username string, action Action, description string, options map[string]string) *Log {
return &Log{
Id: shared.NewObjectId(),
Username: username,
Action: action,
Description: description,
Timestamp: time.Now().Unix(),
Options: options,
}
}
// 审计日志类型
func (this *Log) ActionName() string {
switch this.Action {
case ActionLogin:
return "登录"
}
return ""
}