Skip to content

Commit

Permalink
Fix some bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marksagittarius committed Mar 23, 2022
1 parent e513955 commit 8480abe
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
35 changes: 35 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/httptest"
"maintainman/config"
"maintainman/logger"
"maintainman/model"
"maintainman/route"
"testing"
)

func TestNewApp(t *testing.T) {
app := newApp()
e := httptest.New(t, app)

e.POST("/v1/register").WithJSON(model.ModifyUserJson{
Name: "test1",
Password: "12345678",
DisplayName: "admin",
}).Expect().Status(httptest.StatusOK)

e.POST("/v1/login").WithJSON(model.LoginJson{
Account: "张城玮",
Password: "12345678",
}).Expect().Status(httptest.StatusOK)
}

func newApp() *iris.Application {
app := iris.New()
app.Logger().SetLevel(config.AppConfig.GetString("app.loglevel"))
logger.Logger = app.Logger()
route.Route(app)
return app
}
59 changes: 59 additions & 0 deletions util/interfaceToStirng.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package util

import (
"encoding/json"
"strconv"
)

func Strval(value interface{}) string {
var key string
if value == nil {
return key
}
switch value.(type) {
case float64:
ft := value.(float64)
key = strconv.FormatFloat(ft, 'f', -1, 64)
case float32:
ft := value.(float32)
key = strconv.FormatFloat(float64(ft), 'f', -1, 64)
case int:
it := value.(int)
key = strconv.Itoa(it)
case uint:
it := value.(uint)
key = strconv.Itoa(int(it))
case int8:
it := value.(int8)
key = strconv.Itoa(int(it))
case uint8:
it := value.(uint8)
key = strconv.Itoa(int(it))
case int16:
it := value.(int16)
key = strconv.Itoa(int(it))
case uint16:
it := value.(uint16)
key = strconv.Itoa(int(it))
case int32:
it := value.(int32)
key = strconv.Itoa(int(it))
case uint32:
it := value.(uint32)
key = strconv.Itoa(int(it))
case int64:
it := value.(int64)
key = strconv.FormatInt(it, 10)
case uint64:
it := value.(uint64)
key = strconv.FormatUint(it, 10)
case string:
key = value.(string)
case []byte:
key = string(value.([]byte))
default:
newValue, _ := json.Marshal(value)
key = string(newValue)
}
return key
}

0 comments on commit 8480abe

Please sign in to comment.