Skip to content

Commit

Permalink
polish codes
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiapeng.ljp committed Nov 7, 2022
1 parent 2900cb7 commit 085d14f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
24 changes: 0 additions & 24 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 4 additions & 2 deletions model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestIndex_MarshalJSON(t *testing.T) {

type fields struct {
Keys map[string]IndexKey
Line *IndexLine
Expand Down Expand Up @@ -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",
Expand All @@ -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 {
Expand All @@ -67,4 +68,5 @@ func TestIndex_MarshalJSON(t *testing.T) {
assert.Equalf(t, tt.want, got, "MarshalJSON()")
})
}

}

0 comments on commit 085d14f

Please sign in to comment.