github.com/kotovmak/go-admin@v1.1.1/plugins/admin/models/operation_log.go (about) 1 package models 2 3 import ( 4 "github.com/kotovmak/go-admin/modules/db" 5 "github.com/kotovmak/go-admin/modules/db/dialect" 6 ) 7 8 // OperationLogModel is operation log model structure. 9 type OperationLogModel struct { 10 Base 11 12 Id int64 13 UserId int64 14 Path string 15 Method string 16 Ip string 17 Input string 18 CreatedAt string 19 UpdatedAt string 20 } 21 22 // OperationLog return a default operation log model. 23 func OperationLog() OperationLogModel { 24 return OperationLogModel{Base: Base{TableName: "goadmin_operation_log"}} 25 } 26 27 // Find return a default operation log model of given id. 28 func (t OperationLogModel) Find(id interface{}) OperationLogModel { 29 item, _ := t.Table(t.TableName).Find(id) 30 return t.MapToModel(item) 31 } 32 33 func (t OperationLogModel) SetConn(con db.Connection) OperationLogModel { 34 t.Conn = con 35 return t 36 } 37 38 // New create a new operation log model. 39 func (t OperationLogModel) New(userId int64, path, method, ip, input string) OperationLogModel { 40 41 id, _ := t.Table(t.TableName).Insert(dialect.H{ 42 "user_id": userId, 43 "path": path, 44 "method": method, 45 "ip": ip, 46 "input": input, 47 }) 48 49 t.Id = id 50 t.UserId = userId 51 t.Path = path 52 t.Method = method 53 t.Ip = ip 54 t.Input = input 55 56 return t 57 } 58 59 // MapToModel get the operation log model from given map. 60 func (t OperationLogModel) MapToModel(m map[string]interface{}) OperationLogModel { 61 t.Id = m["id"].(int64) 62 t.UserId = m["user_id"].(int64) 63 t.Path, _ = m["path"].(string) 64 t.Method, _ = m["method"].(string) 65 t.Ip, _ = m["ip"].(string) 66 t.Input, _ = m["input"].(string) 67 t.CreatedAt, _ = m["created_at"].(string) 68 t.UpdatedAt, _ = m["updated_at"].(string) 69 return t 70 }