From ca30e650b46db846b57173b108a9cfe5a0792b42 Mon Sep 17 00:00:00 2001 From: Jeffrey Paul Date: Thu, 7 Nov 2019 13:04:57 -0800 Subject: [PATCH] seems to work now --- .revive.toml | 24 ++++++++++++++++++++++++ Makefile | 4 ++-- go.mod | 9 +++++++++ go.sum | 42 ++++++++++++++++++++++++++++++++++++++++++ main.go | 3 +++ merp.go | 22 +++++++++++----------- models/db.go | 2 +- server.go | 6 +++--- 8 files changed, 95 insertions(+), 17 deletions(-) create mode 100644 .revive.toml diff --git a/.revive.toml b/.revive.toml new file mode 100644 index 0000000..3b7a772 --- /dev/null +++ b/.revive.toml @@ -0,0 +1,24 @@ +severity = "warning" +confidence = 0.8 +errorCode = 1 +warningCode = 1 + +[rule.blank-imports] +[rule.context-as-argument] +[rule.context-keys-type] +[rule.dot-imports] +[rule.error-return] +[rule.error-strings] +[rule.error-naming] +[rule.exported] +[rule.if-return] +[rule.increment-decrement] +[rule.var-naming] +[rule.var-declaration] +[rule.package-comments] +[rule.range] +[rule.receiver-naming] +[rule.time-naming] +[rule.unexported-return] +[rule.indent-error-flow] +[rule.errorf] diff --git a/Makefile b/Makefile index a693ba5..b6933a7 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,8 @@ fmt: go fmt *.go lint: - go get -u github.com/mgechev/revive - revive -formatter friendly -exclude=./vendor/... ./... || exit 1 + which revive || go get -u github.com/mgechev/revive + revive -formatter friendly -config .revive.toml -exclude=./vendor/... ./... || exit 1 test: build-docker-image diff --git a/go.mod b/go.mod index 3ec74e5..f4c1265 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,19 @@ go 1.13 require ( github.com/astaxie/beego v1.12.0 github.com/dn365/gin-zerolog v0.0.0-20171227063204-b43714b00db1 + github.com/fatih/structtag v1.1.0 // indirect github.com/gin-gonic/gin v1.4.0 github.com/google/uuid v1.1.1 github.com/lib/pq v1.2.0 + github.com/mattn/go-colorable v0.1.4 // indirect + github.com/mattn/go-isatty v0.0.10 // indirect + github.com/mattn/go-runewidth v0.0.6 // indirect + github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81 // indirect + github.com/mgechev/revive v0.0.0-20191017201419-88015ccf8e97 // indirect + github.com/olekukonko/tablewriter v0.0.2 // indirect github.com/rs/zerolog v1.16.0 golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf + golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd // indirect + golang.org/x/tools v0.0.0-20191107185733-c07e1c6ef61c // indirect google.golang.org/appengine v1.6.5 // indirect ) diff --git a/go.sum b/go.sum index 1f48ac0..aef9b50 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM= github.com/astaxie/beego v1.12.0 h1:MRhVoeeye5N+Flul5PoVfD9CslfdoH+xqC/xvSQ5u2Y= @@ -18,6 +20,12 @@ github.com/dn365/gin-zerolog v0.0.0-20171227063204-b43714b00db1 h1:qwfOp+dwJnhdR github.com/dn365/gin-zerolog v0.0.0-20171227063204-b43714b00db1/go.mod h1:AAlcXL9Ejp3TUsJRWJtjbIpK3p1L9z987raCTYL17j4= github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4= +github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/structtag v1.0.0 h1:pTHj65+u3RKWYPSGaU290FpI/dXxTaHdVwVwbcPKmEc= +github.com/fatih/structtag v1.0.0/go.mod h1:IKitwq45uXL/yqi5mYghiD3w9H6eTOvI9vnk8tXMphA= +github.com/fatih/structtag v1.1.0 h1:6j4mUV/ES2duvnAzKMFkN6/A5mCaNYPD3xfbAkLLOF8= +github.com/fatih/structtag v1.1.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g= github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ= @@ -37,14 +45,39 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= +github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= +github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= +github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.6 h1:V2iyH+aX9C5fsYCpK60U8BYIvmhqxuOL3JZcqc1NB7k= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/mgechev/dots v0.0.0-20181228164730-18fa4c4b71cc h1:SQHr6jXnsY5YmRoO7RWDcZjmC3PgwPW/xQ9TYJ/SiRY= +github.com/mgechev/dots v0.0.0-20181228164730-18fa4c4b71cc/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg= +github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81 h1:QASJXOGm2RZ5Ardbc86qNFvby9AqkLDibfChMtAg5QM= +github.com/mgechev/dots v0.0.0-20190921121421-c36f7dcfbb81/go.mod h1:KQ7+USdGKfpPjXk4Ga+5XxQM4Lm4e3gAogrreFAYpOg= +github.com/mgechev/revive v0.0.0-20191017201419-88015ccf8e97 h1:/traC0Wb959khmF0vgFqbE8uRhYfauj07hBuMcTFgow= +github.com/mgechev/revive v0.0.0-20191017201419-88015ccf8e97/go.mod h1:37hJOqkogcmT5nmiriskuzkdJ/YhMlZwFSg87NDZbco= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= +github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= +github.com/olekukonko/tablewriter v0.0.2 h1:sq53g+DWf0J6/ceFUHpQ0nAEb6WgM++fq16MZ91cS6o= +github.com/olekukonko/tablewriter v0.0.2/go.mod h1:rSAaSIOAGT9odnlyGlUfAJaoc5w2fSBUmeGDbRWPxyQ= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -80,10 +113,19 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd h1:3x5uuvBgE6oaXJjCOvpCC1IpgJogqQ+PqGGU3ZxAgII= +golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74 h1:4cFkmztxtMslUX2SctSl+blCyXfpzhGOy9LhKAqSMA4= golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191107185733-c07e1c6ef61c h1:Qt1WYboHEeHaS/fP0fLmCKuwYQtLpZ4GkGewvC29TaE= +golang.org/x/tools v0.0.0-20191107185733-c07e1c6ef61c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= diff --git a/main.go b/main.go index 8c331f0..5e8f3aa 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,15 @@ package main import "github.com/rs/zerolog/log" +//revive:disable var Version string var Buildtime string var Builduser string var Buildarch string var Appname string +//revive:enable + func main() { initLogging() identify() diff --git a/merp.go b/merp.go index e3ad09f..d00574b 100644 --- a/merp.go +++ b/merp.go @@ -18,7 +18,7 @@ func thingRegex() *regexp.Regexp { return ThingRegex } -func decodeJson(in []byte) interface{} { +func decodeJSON(in []byte) interface{} { var out interface{} err := json.Unmarshal(in, &out) if err != nil { @@ -28,13 +28,13 @@ func decodeJson(in []byte) interface{} { return out } -func GetLatestMerps() gin.HandlerFunc { - THING_REGEX := thingRegex() +func getLatestMerps() gin.HandlerFunc { + ThingRegex := thingRegex() orm := models.GetOrmObject() h := func(c *gin.Context) { thing := c.Param("thing") - if THING_REGEX.MatchString(thing) == false { + if ThingRegex.MatchString(thing) == false { c.JSON(http.StatusPreconditionFailed, gin.H{ "this": "failed", "status": http.StatusPreconditionFailed, @@ -51,7 +51,7 @@ func GetLatestMerps() gin.HandlerFunc { for _, merp := range merps { outelem := make(map[string]interface{}) outelem["thing"] = merp.Thing - outjs := decodeJson([]byte(merp.Content)) + outjs := decodeJSON([]byte(merp.Content)) if outjs == nil { outelem["content"] = gin.H{} } else { @@ -71,12 +71,12 @@ func GetLatestMerps() gin.HandlerFunc { return h } -func GetLatestMerp() gin.HandlerFunc { - THING_REGEX := thingRegex() +func getLatestMerp() gin.HandlerFunc { + ThingRegex := thingRegex() h := func(c *gin.Context) { thing := c.Param("thing") - if THING_REGEX.MatchString(thing) == false { + if ThingRegex.MatchString(thing) == false { c.JSON(http.StatusPreconditionFailed, gin.H{ "this": "failed", "status": http.StatusPreconditionFailed, @@ -91,17 +91,17 @@ func GetLatestMerp() gin.HandlerFunc { return h } -func HandleNewMerp() gin.HandlerFunc { +func handleNewMerp() gin.HandlerFunc { // server startup time - THING_REGEX := thingRegex() + ThingRegex := thingRegex() // establish db connection *first*, before requests orm := models.GetOrmObject() h := func(c *gin.Context) { // request time thing := c.Param("thing") - if THING_REGEX.MatchString(thing) == false { + if ThingRegex.MatchString(thing) == false { log.Debug().Msgf("%s didnt match", thing) c.JSON(http.StatusPreconditionFailed, gin.H{ "this": "failed", diff --git a/models/db.go b/models/db.go index 3e5d619..723adcf 100644 --- a/models/db.go +++ b/models/db.go @@ -4,7 +4,7 @@ import "os" import "time" import "github.com/astaxie/beego/orm" import "github.com/rs/zerolog/log" -import _ "github.com/lib/pq" +import _ "github.com/lib/pq" //revive:disable-line var ormObject orm.Ormer diff --git a/server.go b/server.go index a800b18..c205734 100644 --- a/server.go +++ b/server.go @@ -54,9 +54,9 @@ func getRouter() *gin.Engine { // call it, it returns the appropriate handler function // so we can execute some code at startup time // and not just request time - r.GET("/merp/for/:thing", HandleNewMerp()) - r.GET("/get/latest/merp/for/:thing", GetLatestMerp()) - r.GET("/get/merps/for/:thing", GetLatestMerps()) + r.GET("/merp/for/:thing", handleNewMerp()) + r.GET("/get/latest/merp/for/:thing", getLatestMerp()) + r.GET("/get/merps/for/:thing", getLatestMerps()) return r }