From ae705e1b4063841cab2b87823cce98c215791ed3 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Sat, 26 Sep 2020 21:45:23 +0800 Subject: [PATCH] refactor operation log new --- control | 2 +- go.mod | 4 ++++ src/models/operation_log.go | 7 +++++++ src/modules/rdb/http/router_log.go | 11 ++--------- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/control b/control index 41c08965..c7ab484f 100755 --- a/control +++ b/control @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash # release version version=3.0.0 diff --git a/go.mod b/go.mod index c962f265..055c5cbb 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,8 @@ require ( github.com/coreos/go-oidc v2.2.1+incompatible github.com/dgryski/go-tsz v0.0.0-20180227144327-03b7d791f4fe github.com/eapache/go-resiliency v1.2.0 // indirect + github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect + github.com/eapache/queue v1.1.0 // indirect github.com/garyburd/redigo v1.6.2 github.com/gin-contrib/pprof v1.3.0 github.com/gin-gonic/gin v1.6.3 @@ -22,6 +24,8 @@ require ( github.com/influxdata/influxdb v1.8.0 github.com/mattn/go-isatty v0.0.12 github.com/mattn/go-sqlite3 v1.14.0 // indirect + github.com/onsi/ginkgo v1.7.0 // indirect + github.com/onsi/gomega v1.4.3 // indirect github.com/open-falcon/rrdlite v0.0.0-20200214140804-bf5829f786ad github.com/pquerna/cachecontrol v0.0.0-20200819021114-67c6ae64274f // indirect github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect diff --git a/src/models/operation_log.go b/src/models/operation_log.go index d2ac3ab3..91d514b9 100644 --- a/src/models/operation_log.go +++ b/src/models/operation_log.go @@ -14,6 +14,13 @@ type OperationLog struct { Detail string `json:"detail"` } +func (ol *OperationLog) New() error { + ol.Clock = time.Now().Unix() + ol.Id = 0 + _, err := DB["rdb"].Insert(ol) + return err +} + func OperationLogNew(username, rescl string, resid interface{}, detail string) error { now := time.Now().Unix() obj := OperationLog{ diff --git a/src/modules/rdb/http/router_log.go b/src/modules/rdb/http/router_log.go index 24cbe7a6..1c4e2708 100644 --- a/src/modules/rdb/http/router_log.go +++ b/src/modules/rdb/http/router_log.go @@ -63,15 +63,8 @@ func operationLogResGets(c *gin.Context) { }, nil) } -type oplogForm struct { - Username string `json:"username"` - ResCl string `json:"rescl"` - ResID string `json:"resid"` - Detail string `json:"detail"` -} - func v1OperationLogResPost(c *gin.Context) { - var f oplogForm + var f models.OperationLog bind(c, &f) - renderMessage(c, models.OperationLogNew(f.Username, f.ResCl, f.ResID, f.Detail)) + renderMessage(c, f.New()) }