From 1f2e18b7130e279dfa8f5a02e762833a5a0ed8b7 Mon Sep 17 00:00:00 2001 From: Kodai Aoyama Date: Wed, 11 May 2022 23:23:07 +0900 Subject: [PATCH 1/3] fix db query result order --- command/cmd/api.go | 7 +++---- command/go.mod | 1 + command/go.sum | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/command/cmd/api.go b/command/cmd/api.go index 6932f90..4febfec 100644 --- a/command/cmd/api.go +++ b/command/cmd/api.go @@ -11,7 +11,6 @@ import ( "os" "reflect" "regexp" - "sort" "strconv" "strings" "time" @@ -32,6 +31,7 @@ import ( "github.com/spf13/cobra" // valid usage. _ "github.com/mattn/go-sqlite3" + "github.com/iancoleman/orderedmap" ) var ( @@ -441,16 +441,15 @@ func contentBuilder(contents map[int]map[string]map[string]interface{}) func(req return body{http.StatusInternalServerError, "", []apiResponse{}} } defer rows.Close() - dummy := []map[string]json.RawMessage{} + dummy := []*orderedmap.OrderedMap{} errJSON := json.Unmarshal([]byte(dummyJSON), &dummy) if errJSON != nil { log.Fatal(errJSON) } keys := []string{} - for k := range dummy[0] { + for _,k := range dummy[0].Keys() { keys = append(keys, k) } - sort.Strings(keys) count := len(keys) results := []map[string]string{} for rows.Next() { diff --git a/command/go.mod b/command/go.mod index 136c430..37bb7fc 100644 --- a/command/go.mod +++ b/command/go.mod @@ -9,6 +9,7 @@ require ( github.com/eknkc/pug v0.0.0-20180224090515-607e1323ff9d github.com/fatih/color v1.13.0 github.com/go-sql-driver/mysql v1.6.0 + github.com/iancoleman/orderedmap v0.2.0 github.com/kpango/gache v1.2.7 github.com/labstack/echo-contrib v0.12.0 github.com/labstack/echo/v4 v4.7.2 diff --git a/command/go.sum b/command/go.sum index 7528494..dc97d77 100644 --- a/command/go.sum +++ b/command/go.sum @@ -166,6 +166,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA= +github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf h1:WfD7VjIE6z8dIvMsI4/s+1qr5EL+zoIGev1BQj1eoJ8= github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg= From a9bdbb8c6a990b2f884e2df9c2dfe3420bb3625d Mon Sep 17 00:00:00 2001 From: Kodai Aoyama Date: Wed, 11 May 2022 23:28:15 +0900 Subject: [PATCH 2/3] update README --- README.ja.md | 21 +---- README.md | 67 +++++++--------- samples/serve-dynamic-html/README.ja.md | 16 ---- samples/serve-dynamic-html/README.md | 16 ---- samples/serve-dynamic-json/README.ja.md | 16 ---- samples/serve-dynamic-json/README.md | 16 ---- samples/serve-static-html/README.ja.md | 16 ---- samples/serve-static-html/README.md | 16 ---- samples/serve-static-json/README.ja.md | 76 ------------------- samples/serve-static-json/README.md | 76 ------------------- .../serve-static-json/tuna-mayonnaise.json | 1 - 11 files changed, 31 insertions(+), 306 deletions(-) delete mode 100644 samples/serve-dynamic-html/README.ja.md delete mode 100644 samples/serve-dynamic-html/README.md delete mode 100644 samples/serve-dynamic-json/README.ja.md delete mode 100644 samples/serve-dynamic-json/README.md delete mode 100644 samples/serve-static-html/README.ja.md delete mode 100644 samples/serve-static-html/README.md delete mode 100644 samples/serve-static-json/README.ja.md delete mode 100644 samples/serve-static-json/README.md delete mode 100644 samples/serve-static-json/tuna-mayonnaise.json diff --git a/README.ja.md b/README.ja.md index 8a19b2d..634b4ab 100644 --- a/README.ja.md +++ b/README.ja.md @@ -72,7 +72,7 @@ brew upgrade tuna ```sh # wget または curl でインストール ## releasesタブの最新のバージョンを指定してください。 -VERSION=v0.0.19 +VERSION=v0.0.24 ## 利用OSを指定してください。 OS=linux_amd64 ## wget経由の場合 @@ -169,24 +169,6 @@ WEB APIにリクエストし、そのレスポンスを利用できます。 2. TUNA-Mayonnaise(ツナマヨ)は、ヘルスチェックを `/health` で提供します。 3. TUNA-Mayonnaise(ツナマヨ)は、Labeled Tab-separated Values ( `LTSV` ) フォーマット形式でログ出力します。 -## 活用例 - -### 1. 静的なJSONを返すサーバー作成 - -詳しくは[こちら](samples/serve-static-json/README.ja.md) - -### 2. 静的なHTMLを返すサーバー作成 - -詳しくは[こちら](samples/serve-static-html/README.ja.md) - -### 3. 外部APIからのレスポンスを元に、動的なJSONを返すサーバー作成 - -詳しくは[こちら](samples/serve-dynamic-json/README.ja.md) - -### 4. 外部APIからのレスポンスを元に、動的なHTMLを返すサーバー作成 - -詳しくは[こちら](samples/serve-dynamic-html/README.ja.md) - ## 依存関係 TUNA-Mayonnaise(ツナマヨ)は、多くのOSSによって成り立ってます。 @@ -202,6 +184,7 @@ TUNA-Mayonnaise(ツナマヨ)は、多くのOSSによって成り立って | [github.com/eknkc/pug](https://github.com/eknkc/pug) | MIT License | | [github.com/fatih/color](https://github.com/fatih/color) | MIT License | | [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) | MPL-2.0 License | + | [github.com/iancoleman/orderedmap](https://github.com/iancoleman/orderedmap) | MIT License | | [github.com/kpango/gache](https://github.com/kpango/gache) | MIT License | | [github.com/labstack/echo](https://github.com/labstack/echo) | MIT License | | [github.com/labstack/echo-contrib](https://github.com/labstack/echo-contrib) | MIT License | diff --git a/README.md b/README.md index c548fd8..7c6feca 100644 --- a/README.md +++ b/README.md @@ -18,25 +18,33 @@ TUNA-Mayonnaise is a CommandLineTool to generate and serve JSON/HTML on the node
CLICK -- [Why](#why) -- [Get Started](#get-started) - - [Install](#install) - - [Usage](#usage) -- [Tool Features](#tool-features) - - [Template Engine](#template-engine) - - [API](#api) - - [Database](#database) -- [API Features](#api-features) - - [Monitoring](#monitoring) -- [UseCases](#usecases) - - [1. Serve Static JSON](#1-serve-static-json) - - [2. Serve Static HTML](#2-serve-static-html) - - [3. Serve Dynamic JSON](#3-serve-dynamic-json) - - [4. Serve Dynamic HTML](#4-serve-dynamic-html) -- [Dependencies](#dependencies) - - [BACKEND Dependencies](#backend-dependencies) - - [FRONTEND Dependencies](#frontend-dependencies) - - [FRONTEND DEV Dependencies](#frontend-dev-dependencies) +- [!tuna-mayonnaise](#) + - [Table of Contents](#table-of-contents) + - [Why](#why) + - [Get Started](#get-started) + - [Install](#install) + - [For MacOS (Homebrew)](#for-macos-homebrew) + - [For Others (Binary Releases)](#for-others-binary-releases) + - [Usage](#usage) + - [1. Launch a tool on your browser](#1-launch-a-tool-on-your-browser) + - [2. Serve your JSON/HTML](#2-serve-your-jsonhtml) + - [Tool Features](#tool-features) + - [Template Engine](#template-engine) + - [API](#api) + - [Database](#database) + - [Connection Options](#connection-options) + - [TLS / SSL](#tls--ssl) + - [API Features](#api-features) + - [Monitoring](#monitoring) + - [UseCases](#usecases) + - [1. Serve Static JSON](#1-serve-static-json) + - [2. Serve Static HTML](#2-serve-static-html) + - [3. Serve Dynamic JSON](#3-serve-dynamic-json) + - [4. Serve Dynamic HTML](#4-serve-dynamic-html) + - [Dependencies](#dependencies) + - [BACKEND Dependencies](#backend-dependencies) + - [FRONTEND Dependencies](#frontend-dependencies) + - [FRONTEND DEV Dependencies](#frontend-dev-dependencies)
@@ -74,7 +82,7 @@ you can download a binary release [here](https://github.com/solaoi/tuna-mayonnai ```sh # Install with wget or curl ## set the latest version on releases. -VERSION=v0.0.19 +VERSION=v0.0.24 ## set the OS you use. OS=linux ## case you use wget @@ -172,24 +180,6 @@ List of metrics includes two stats. 3. TUNA-Mayonnaise Logging with Labeled Tab-separated Values ( `LTSV` ) format. -## UseCases - -### 1. Serve Static JSON - -see [here](samples/serve-static-json/README.md). - -### 2. Serve Static HTML - -see [here](samples/serve-static-html/README.md). - -### 3. Serve Dynamic JSON - -see [here](samples/serve-dynamic-json/README.md). - -### 4. Serve Dynamic HTML - -see [here](samples/serve-dynamic-html/README.md). - ## Dependencies TUNA-Mayonnaise stands on the shoulder of many great open source libraries, in lexical order: @@ -205,6 +195,7 @@ TUNA-Mayonnaise stands on the shoulder of many great open source libraries, in l | [github.com/eknkc/pug](https://github.com/eknkc/pug) | MIT License | | [github.com/fatih/color](https://github.com/fatih/color) | MIT License | | [github.com/go-sql-driver/mysql](https://github.com/go-sql-driver/mysql) | MPL-2.0 License | + | [github.com/iancoleman/orderedmap](https://github.com/iancoleman/orderedmap) | MIT License | | [github.com/kpango/gache](https://github.com/kpango/gache) | MIT License | | [github.com/labstack/echo](https://github.com/labstack/echo) | MIT License | | [github.com/labstack/echo-contrib](https://github.com/labstack/echo-contrib) | MIT License | diff --git a/samples/serve-dynamic-html/README.ja.md b/samples/serve-dynamic-html/README.ja.md deleted file mode 100644 index 1581686..0000000 --- a/samples/serve-dynamic-html/README.ja.md +++ /dev/null @@ -1,16 +0,0 @@ - - -
-CLICK - -- [活用例 - 外部APIからのレスポンスを元に、動的なHTMLを返すサーバー作成 -](#%E6%B4%BB%E7%94%A8%E4%BE%8B---%E5%A4%96%E9%83%A8api%E3%81%8B%E3%82%89%E3%81%AE%E3%83%AC%E3%82%B9%E3%83%9D%E3%83%B3%E3%82%B9%E3%82%92%E5%85%83%E3%81%AB%E5%8B%95%E7%9A%84%E3%81%AAhtml%E3%82%92%E8%BF%94%E3%81%99%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E4%BD%9C%E6%88%90--) - - [工事中](#%E5%B7%A5%E4%BA%8B%E4%B8%AD) - -
- - -# 活用例 - 外部APIからのレスポンスを元に、動的なHTMLを返すサーバー作成 - - -*他の言語で読む:[English](README.md)、[日本語](README.ja.md)* - -## 工事中 diff --git a/samples/serve-dynamic-html/README.md b/samples/serve-dynamic-html/README.md deleted file mode 100644 index 427720e..0000000 --- a/samples/serve-dynamic-html/README.md +++ /dev/null @@ -1,16 +0,0 @@ - - -
-CLICK - -- [UseCase - Serve Dynamic HTML -](#usecase---serve-dynamic-html--) - - [TBU](#tbu) - -
- - -# UseCase - Serve Dynamic HTML - - -*Read this in other languages: [English](README.md), [日本語](README.ja.md).* - -### TBU diff --git a/samples/serve-dynamic-json/README.ja.md b/samples/serve-dynamic-json/README.ja.md deleted file mode 100644 index 4d3490e..0000000 --- a/samples/serve-dynamic-json/README.ja.md +++ /dev/null @@ -1,16 +0,0 @@ - - -
-CLICK - -- [活用例 - 外部APIからのレスポンスを元に、動的なJSONを返すサーバー作成 -](#%E6%B4%BB%E7%94%A8%E4%BE%8B---%E5%A4%96%E9%83%A8api%E3%81%8B%E3%82%89%E3%81%AE%E3%83%AC%E3%82%B9%E3%83%9D%E3%83%B3%E3%82%B9%E3%82%92%E5%85%83%E3%81%AB%E5%8B%95%E7%9A%84%E3%81%AAjson%E3%82%92%E8%BF%94%E3%81%99%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E4%BD%9C%E6%88%90--) - - [工事中](#%E5%B7%A5%E4%BA%8B%E4%B8%AD) - -
- - -# 活用例 - 外部APIからのレスポンスを元に、動的なJSONを返すサーバー作成 - - -*他の言語で読む:[English](README.md)、[日本語](README.ja.md)* - -## 工事中 diff --git a/samples/serve-dynamic-json/README.md b/samples/serve-dynamic-json/README.md deleted file mode 100644 index 3bf4365..0000000 --- a/samples/serve-dynamic-json/README.md +++ /dev/null @@ -1,16 +0,0 @@ - - -
-CLICK - -- [UseCase - Serve Dynamic JSON -](#usecase---serve-dynamic-json--) - - [TBU](#tbu) - -
- - -# UseCase - Serve Dynamic JSON - - -*Read this in other languages: [English](README.md), [日本語](README.ja.md).* - -### TBU diff --git a/samples/serve-static-html/README.ja.md b/samples/serve-static-html/README.ja.md deleted file mode 100644 index 95f65c9..0000000 --- a/samples/serve-static-html/README.ja.md +++ /dev/null @@ -1,16 +0,0 @@ - - -
-CLICK - -- [活用例 - 静的なHTMLを返すサーバー作成 -](#%E6%B4%BB%E7%94%A8%E4%BE%8B---%E9%9D%99%E7%9A%84%E3%81%AAhtml%E3%82%92%E8%BF%94%E3%81%99%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E4%BD%9C%E6%88%90--) - - [工事中](#%E5%B7%A5%E4%BA%8B%E4%B8%AD) - -
- - -# 活用例 - 静的なHTMLを返すサーバー作成 - - -*他の言語で読む:[English](README.md)、[日本語](README.ja.md)* - -## 工事中 diff --git a/samples/serve-static-html/README.md b/samples/serve-static-html/README.md deleted file mode 100644 index 7bf2484..0000000 --- a/samples/serve-static-html/README.md +++ /dev/null @@ -1,16 +0,0 @@ - - -
-CLICK - -- [UseCase - Serve Static HTML -](#usecase---serve-static-html--) - - [TBU](#tbu) - -
- - -# UseCase - Serve Static HTML - - -*Read this in other languages: [English](README.md), [日本語](README.ja.md).* - -### TBU diff --git a/samples/serve-static-json/README.ja.md b/samples/serve-static-json/README.ja.md deleted file mode 100644 index 8b57ea6..0000000 --- a/samples/serve-static-json/README.ja.md +++ /dev/null @@ -1,76 +0,0 @@ -# 活用例 - 静的なJSONを返すサーバー作成 - - -*他の言語で読む:[English](README.md)、[日本語](README.ja.md)* - -## 目次 - - - -
-CLICK - -- [手順](#%E6%89%8B%E9%A0%86) - - [1. 設定ファイルをダウンロード](#1-%E8%A8%AD%E5%AE%9A%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E3%83%80%E3%82%A6%E3%83%B3%E3%83%AD%E3%83%BC%E3%83%89) - - [2. 設定を編集](#2-%E8%A8%AD%E5%AE%9A%E3%82%92%E7%B7%A8%E9%9B%86) - - [3. 設定を元にサーバーを作成](#3-%E8%A8%AD%E5%AE%9A%E3%82%92%E5%85%83%E3%81%AB%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E3%82%92%E4%BD%9C%E6%88%90) - -
- - -## 手順 - -### 1. 設定ファイルをダウンロード - -[こちら](https://raw.githubusercontent.com/solaoi/tuna-mayonnaise/main/samples/serve-static-json/tuna-mayonnaise.json)から設定ファイルをダウンロードし、`tuna-mayonnaise.json` という名前で保存します。 - -### 2. 設定を編集 - -先程ダウンロードした `tuna-mayonnaise.json` があるディレクトリに移動し、下記コマンドを実行します。 - -``` -tuna tool -``` - -実行すると、下記画面でブラウザが開きます。 - -スクリーンショット 2021-02-11 16 05 45 - -#### エンドポイントを無効化する場合 - -Booleanコンポーネントでチェックを外すと、そのエンドポイントは提供されなくなります。 - -#### 返却するJSONを変更する場合 - -JSONコンポーネントのテキストボックスを編集してください。 - -デフォルト) - -``` -{"name": "value"} -``` - -#### 提供するエンドポイントのパスを変更する場合 - -Pathコンポーネントのテキストボックスを編集してください。 - -デフォルト) - -``` -/serve-static-json -``` - -### 3. 設定を元にサーバーを作成 - -`tuna-mayonnaise.json` があるディレクトリで、下記コマンドを実行します。 - -``` -tuna api -``` - -設定したパスとともに `http://localhost:8080` にアクセスしてみましょう。 - -デフォルト) - -``` -http://localhost:8080/serve-static-json -``` diff --git a/samples/serve-static-json/README.md b/samples/serve-static-json/README.md deleted file mode 100644 index 7f55cab..0000000 --- a/samples/serve-static-json/README.md +++ /dev/null @@ -1,76 +0,0 @@ -# UseCase - Serve Static JSON - - -*Read this in other languages: [English](README.md), [日本語](README.ja.md).* - -## Table of Contents - - - -
-CLICK - -- [3 STEP Usage](#3-step-usage) - - [1. Download a configuration](#1-download-a-configuration) - - [2. Edit a configuration](#2-edit-a-configuration) - - [3. Serve APIs on a configuration](#3-serve-apis-on-a-configuration) - -
- - -## 3 STEP Usage - -### 1. Download a configuration - -download [this](https://raw.githubusercontent.com/solaoi/tuna-mayonnaise/main/samples/serve-static-json/tuna-mayonnaise.json), and save as `tuna-mayonnaise.json` . - -### 2. Edit a configuration - -change directory to the one that has `tuna-mayonnaise.json`, then execute this command. - -``` -tuna tool -``` - -you would see like below. - -スクリーンショット 2021-02-11 16 05 45 - -#### Disable this Endpoint - -you should uncheck this Boolean Component - -#### Change this content - -you should edit text on this JSON Component. - -default) - -``` -{"name": "value"} -``` - -#### Change this Path of Endpoint - -you should edit text on this Path Component. - -default) - -``` -/serve-static-json -``` - -### 3. Serve APIs on a configuration - -change directory to the one that has `tuna-mayonnaise.json`, then execute this command. - -``` -tuna api -``` - -Let's access `http://localhost:8080` with your paths :) - -default) - -``` -http://localhost:8080/serve-static-json -``` diff --git a/samples/serve-static-json/tuna-mayonnaise.json b/samples/serve-static-json/tuna-mayonnaise.json deleted file mode 100644 index a4605a4..0000000 --- a/samples/serve-static-json/tuna-mayonnaise.json +++ /dev/null @@ -1 +0,0 @@ -{"comments":[],"id":"tuna-mayonnaise@0.0.1","nodes":{"1":{"data":{"content":"{\"name\": \"value\"}","contentType":"application/json; charset=utf-8","enabledFlag":true,"output":"{\"name\": \"value\"}","path":"/serve-static-json"},"id":1,"inputs":{"content":{"connections":[{"data":{"pins":[]},"node":2,"output":"json"}]},"enabledFlag":{"connections":[{"data":{"pins":[]},"node":3,"output":"boolean"}]},"path":{"connections":[{"data":{"pins":[]},"node":4,"output":"path"}]}},"name":"Endpoint","outputs":{},"position":[401,-207.5]},"2":{"data":{"json":"{\"name\": \"value\"}","output":"{\"name\": \"value\"}"},"id":2,"inputs":{},"name":"JSON","outputs":{"json":{"connections":[{"data":{"pins":[]},"input":"content","node":1}]}},"position":[0,-171.5]},"3":{"data":{"boolean":true,"output":true},"id":3,"inputs":{},"name":"Boolean","outputs":{"boolean":{"connections":[{"data":{"pins":[]},"input":"enabledFlag","node":1}]}},"position":[0,-346.5]},"4":{"data":{"output":"/serve-static-json","path":"/serve-static-json"},"id":4,"inputs":{},"name":"Path","outputs":{"path":{"connections":[{"data":{"pins":[]},"input":"path","node":1}]}},"position":[0,171.5]}}} \ No newline at end of file From f24814fb221f05988873d81aee7b2ddc36b9e432 Mon Sep 17 00:00:00 2001 From: Kodai Aoyama Date: Wed, 11 May 2022 23:31:01 +0900 Subject: [PATCH 3/3] format --- command/cmd/api.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/command/cmd/api.go b/command/cmd/api.go index 4febfec..887f307 100644 --- a/command/cmd/api.go +++ b/command/cmd/api.go @@ -19,6 +19,7 @@ import ( "github.com/eknkc/pug" // valid usage. _ "github.com/go-sql-driver/mysql" + "github.com/iancoleman/orderedmap" "github.com/kpango/gache" prom "github.com/labstack/echo-contrib/prometheus" "github.com/labstack/echo/v4" @@ -31,7 +32,6 @@ import ( "github.com/spf13/cobra" // valid usage. _ "github.com/mattn/go-sqlite3" - "github.com/iancoleman/orderedmap" ) var ( @@ -118,7 +118,7 @@ func isJSONorHTMLNode(name string) bool { } func isSQLInjectionParams(value string) bool { - regs := [...] *regexp.Regexp { + regs := [...]*regexp.Regexp{ regexp.MustCompile(`(%27)|(')|(--)|(%23)|(#)`), regexp.MustCompile(`((%3D)|(=))[^\n]*((%27)|(')|(--)|(%3B)|(;))`), regexp.MustCompile(`w*((%27)|('))((%6F)|o|(%4F))((%72)|r|(%52))`), @@ -126,8 +126,10 @@ func isSQLInjectionParams(value string) bool { } val := strings.ToLower(value) for _, reg := range regs { - isSQLInjection := reg.MatchString(val) - if isSQLInjection {return true} + isSQLInjection := reg.MatchString(val) + if isSQLInjection { + return true + } } return false } @@ -344,9 +346,9 @@ func contentBuilder(contents map[int]map[string]map[string]interface{}) func(req return body{http.StatusBadRequest, "", []apiResponse{}} } for k, v := range tmp { - if (isSQLInjectionParams(v)){ + if isSQLInjectionParams(v) { if reqDBCounter != nil { - reqDBCounter.WithLabelValues(dbType, "Reject SQL Injection: " + v).Inc() + reqDBCounter.WithLabelValues(dbType, "Reject SQL Injection: "+v).Inc() } return body{http.StatusBadRequest, "", []apiResponse{}} } @@ -447,7 +449,7 @@ func contentBuilder(contents map[int]map[string]map[string]interface{}) func(req log.Fatal(errJSON) } keys := []string{} - for _,k := range dummy[0].Keys() { + for _, k := range dummy[0].Keys() { keys = append(keys, k) } count := len(keys)