package main import ( "encoding/json" "fmt" "testing" "github.com/shopspring/decimal" ) func Test_A(t *testing.T) { input := 2.499 dec := decimal.NewFromFloat(input) fmt.Println(dec.Round(0)) } func Test_B(t *testing.T) { type A struct { ProjectId int64 `json:"project_id"` Type int `json:"type"` OperationId string `json:"operation_id"` Count int `json:"count"` Timestamp int64 `json:"timestamp"` ExtraData string `json:"extra_data"` } a := A{ ProjectId: 1, Count: 10, OperationId: "jfhkdfjhsdkjf", } aByte, err := jsonTest(a) if err != nil { t.Log(err) } var b A t.Log(string(aByte)) err = json.Unmarshal(aByte, &b) if err != nil { t.Log(err) } t.Log(b.OperationId, "11111111") } func jsonTest(message interface{}) ([]byte, error) { messageByte, err := json.Marshal(message) if err != nil { return nil, err } return messageByte, nil } func jsonTest(message interface{}) ([]byte, error) { messageByte, err := json.Marshal(message) if err != nil { return nil, err } return messageByte, nil }