diff --git a/model.go b/model.go index 1a178196..21628eb3 100644 --- a/model.go +++ b/model.go @@ -133,30 +133,6 @@ type Index struct { LogReduceBlackListDict []string `json:"log_reduce_black_list,omitempty"` } -func (u *Index) MarshalJSON() ([]byte, error) { - rst := make(map[string]interface{}) - rst["log_reduce"] = u.LogReduce - if len(u.Keys) > 0 { - rst["keys"] = u.Keys - } - if u.Line != nil { - rst["line"] = u.Line - } - if u.Ttl > 0 { - rst["ttl"] = u.Ttl - } - if u.MaxTextLen > 0 { - rst["max_text_len"] = u.MaxTextLen - } - if len(u.LogReduceWhiteListDict) > 0 { - rst["log_reduce_white_list"] = u.LogReduceWhiteListDict - } - if len(u.LogReduceBlackListDict) > 0 { - rst["log_reduce_black_list"] = u.LogReduceBlackListDict - } - return json.Marshal(rst) -} - // CreateDefaultIndex return a full text index config func CreateDefaultIndex() *Index { return &Index{ diff --git a/model_test.go b/model_test.go index e2d12f29..f6d5662d 100644 --- a/model_test.go +++ b/model_test.go @@ -9,6 +9,7 @@ import ( ) func TestIndex_MarshalJSON(t *testing.T) { + type fields struct { Keys map[string]IndexKey Line *IndexLine @@ -39,7 +40,7 @@ func TestIndex_MarshalJSON(t *testing.T) { Ttl: 2, MaxTextLen: 3, }, - want: []byte(`{"log_reduce":false,"max_text_len":3,"ttl":2}`), + want: []byte(`{"ttl":2,"max_text_len":3,"log_reduce":false}`), }, { name: "white & black", @@ -48,7 +49,7 @@ func TestIndex_MarshalJSON(t *testing.T) { LogReduceBlackListDict: []string{"key2"}, LogReduce: true, }, - want: []byte(`{"log_reduce":true,"log_reduce_black_list":["key2"],"log_reduce_white_list":["key1"]}`), + want: []byte(`{"log_reduce":true,"log_reduce_white_list":["key1"],"log_reduce_black_list":["key2"]}`), }, } for _, tt := range tests { @@ -67,4 +68,5 @@ func TestIndex_MarshalJSON(t *testing.T) { assert.Equalf(t, tt.want, got, "MarshalJSON()") }) } + }