-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e513955
commit 8480abe
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |