From b61ecc2a01e54a50f92c30ff93a5e2edd33942d9 Mon Sep 17 00:00:00 2001 From: Xiaochao Li <48587632+Xiaochao8@users.noreply.github.com> Date: Mon, 20 Nov 2023 10:44:37 +0800 Subject: [PATCH] unique version names in multiple versions' key API (#2812) --- api/v2/translation/handler_trans.go | 9 ++++++--- go.mod | 1 + go.sum | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/v2/translation/handler_trans.go b/api/v2/translation/handler_trans.go index 531bd628b..ffd32371c 100644 --- a/api/v2/translation/handler_trans.go +++ b/api/v2/translation/handler_trans.go @@ -6,15 +6,17 @@ package translation import ( - "io/ioutil" + "io" + "strings" + "sgtnserver/api" "sgtnserver/internal/common" "sgtnserver/internal/logger" "sgtnserver/internal/sgtnerror" "sgtnserver/modules/translation" "sgtnserver/modules/translation/translationservice" - "strings" + "github.com/StudioSol/set" "github.com/emirpasic/gods/sets/linkedhashset" "github.com/gin-gonic/gin" jsoniter "github.com/json-iterator/go" @@ -311,6 +313,7 @@ func GetMultiVersionsKey(c *gin.Context) { var versions []string if params.Versions != api.AllVersions { versions = strings.Split(params.Versions, common.ParamSep) + versions = set.NewLinkedHashSetString(versions...).AsSlice() } var result []interface{} @@ -354,7 +357,7 @@ func GetStringByPost(c *gin.Context) { } if c.Request.Body != nil { - if bts, err := ioutil.ReadAll(c.Request.Body); err != nil { + if bts, err := io.ReadAll(c.Request.Body); err != nil { api.AbortWithError(c, sgtnerror.StatusBadRequest.WrapErrorWithMessage(err, "fail to read request body")) return } else { diff --git a/go.mod b/go.mod index ac8404fb6..6776f1f22 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module sgtnserver go 1.20 require ( + github.com/StudioSol/set v1.0.0 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 github.com/anargu/gin-brotli v0.0.0-20220116052358-12bf532d5267 github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 diff --git a/go.sum b/go.sum index a53fd024e..829e0b90f 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6Xge github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/StudioSol/set v1.0.0 h1:G27J71la+Da08WidabBkoRrvPLTa4cdCn0RjvyJ5WKQ= +github.com/StudioSol/set v1.0.0/go.mod h1:hIUNZPo6rEGF43RlPXHq7Fjmf+HkVJBqAjtK7Z9LoIU= github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 h1:ZBbLwSJqkHBuFDA6DUhhse0IGJ7T5bemHyNILUjvOq4= github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2/go.mod h1:VSw57q4QFiWDbRnjdX8Cb3Ow0SFncRw+bA/ofY6Q83w= github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=