Fix incorrect attribute conversion

This commit is contained in:
Nise Void 2018-05-22 12:07:18 +02:00
parent 6bc66975db
commit 9374108288
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3
2 changed files with 30 additions and 5 deletions

View File

@ -43,11 +43,7 @@ func pmax(c echo.Context) error {
if len(attr) < 2 { if len(attr) < 2 {
return c.NoContent(400) return c.NoContent(400)
} }
if len(attr) == 2 { attr = convertAttribute(attr)
attr = strings.ToUpper(attr[:2])
} else {
attr = strings.ToUpper(attr[:2]) + strings.ToLower(attr[2:])
}
date, err := time.Parse(time.RFC3339, c.Param(`date`)) date, err := time.Parse(time.RFC3339, c.Param(`date`))
if err != nil { if err != nil {
@ -61,3 +57,12 @@ func pmax(c echo.Context) error {
return c.JSON(200, data) return c.JSON(200, data)
} }
func convertAttribute(attr string) string {
attr = strings.ToUpper(attr[:1]) + strings.ToLower(attr[1:])
attr = strings.Replace(attr, `gem`, `Gem`, -1)
attr = strings.Replace(attr, `max`, `Max`, -1)
return attr
}

20
server/main_test.go Normal file
View File

@ -0,0 +1,20 @@
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestConvertAttribute(t *testing.T) {
var data = map[string]string{
`cgem`: `CGem`,
`ep`: `Ep`,
`PMAX`: `PMax`,
`Test`: `Test`,
}
for in, expected := range data {
assert.Equal(t, expected, convertAttribute(in))
}
}