test
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/jx-print/globals"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"github.com/dchest/captcha"
|
||||
@@ -166,3 +167,27 @@ func BuildErr(errs []error) (err error) {
|
||||
}
|
||||
return fmt.Errorf(errStr.String())
|
||||
}
|
||||
|
||||
func Format4Output(obj interface{}, isSingleLine bool) (retVal string) {
|
||||
retVal, ok := obj.(string)
|
||||
if !ok {
|
||||
var (
|
||||
result []byte
|
||||
err error
|
||||
)
|
||||
if isSingleLine {
|
||||
if result, err = json.Marshal(obj); err == nil {
|
||||
retVal = string(result)
|
||||
}
|
||||
} else {
|
||||
if result, err = json.MarshalIndent(obj, "", "\t"); err == nil {
|
||||
retVal = string(result)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Infof("Format4Output Marshal:%v failed with error:%v", obj, err)
|
||||
retVal = fmt.Sprintf("%v", obj)
|
||||
}
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user