commit
534cb183f7
@ -0,0 +1,17 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: clone
|
||||
|
||||
steps:
|
||||
- name: Test
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- go env -w GO111MODULE=on
|
||||
- go env -w GOPROXY=https://goproxy.cn,direct
|
||||
- go test -v ./...
|
||||
- name: Benchmark
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- go env -w GO111MODULE=on
|
||||
- go env -w GOPROXY=https://goproxy.cn,direct
|
||||
- go test -bench=. -benchmem
|
@ -0,0 +1,8 @@
|
||||
.env
|
||||
.git
|
||||
.svn
|
||||
.idea
|
||||
.vscode
|
||||
*.log
|
||||
gomod.sh
|
||||
/vendor/
|
@ -0,0 +1,47 @@
|
||||
package gojson
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
func Encode(v interface{}) (string, error) {
|
||||
bytes, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(bytes), nil
|
||||
}
|
||||
|
||||
func MarshalToString(msg interface{}) (string, error) {
|
||||
j, e := json.Marshal(msg)
|
||||
if e != nil {
|
||||
return "", e
|
||||
}
|
||||
return string(j), nil
|
||||
}
|
||||
|
||||
func JsonDecode(data string) (map[string]interface{}, error) {
|
||||
var dat map[string]interface{}
|
||||
err := json.Unmarshal([]byte(data), &dat)
|
||||
return dat, err
|
||||
}
|
||||
|
||||
func JsonDecodeNoError(data string) map[string]interface{} {
|
||||
var dat map[string]interface{}
|
||||
_ = json.Unmarshal([]byte(data), &dat)
|
||||
return dat
|
||||
}
|
||||
|
||||
func JsonEncode(data interface{}) (string, error) {
|
||||
jsons, err := json.Marshal(data)
|
||||
return string(jsons), err
|
||||
}
|
||||
|
||||
func JsonEncodeNoError(data interface{}) string {
|
||||
jsons, _ := json.Marshal(data)
|
||||
return string(jsons)
|
||||
}
|
||||
|
||||
func JsonDecodesNoError(data string) []string {
|
||||
var dat []string
|
||||
_ = json.Unmarshal([]byte(data), &dat)
|
||||
return dat
|
||||
}
|
@ -0,0 +1 @@
|
||||
package gojson
|
@ -0,0 +1,3 @@
|
||||
package gojson
|
||||
|
||||
const Version = "1.0.0"
|
@ -0,0 +1,7 @@
|
||||
package gojson
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
t.Log(Version)
|
||||
}
|
Loading…
Reference in new issue