Skip to content

Commit

Permalink
feat: change json formater (zincsearch#457)
Browse files Browse the repository at this point in the history
* feat: change json formater
* fix: upgrade
  • Loading branch information
hengfeiyang authored Aug 24, 2022
1 parent 12dedcc commit 5dba586
Show file tree
Hide file tree
Showing 41 changed files with 66 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pkg/core/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (

"github.com/blugelabs/bluge"
"github.com/blugelabs/bluge/analysis"
"github.com/goccy/go-json"
"golang.org/x/sync/errgroup"

"github.com/zinclabs/zinc/pkg/meta"
zincanalysis "github.com/zinclabs/zinc/pkg/uquery/analysis"
"github.com/zinclabs/zinc/pkg/zutils/hash/rendezvous"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

type Index struct {
Expand Down
3 changes: 1 addition & 2 deletions pkg/core/index_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import (
"strings"
"time"

"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/errors"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

// CreateDocument inserts or updates a document in the zinc index
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/index_shards_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
"time"

"github.com/blugelabs/bluge"
"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/config"
"github.com/zinclabs/zinc/pkg/meta"
zincanalysis "github.com/zinclabs/zinc/pkg/uquery/analysis"
"github.com/zinclabs/zinc/pkg/zutils"
"github.com/zinclabs/zinc/pkg/zutils/flatten"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

// BuildBlugeDocumentFromJSON returns the bluge document for the json document. It also updates the mapping for the fields if not found.
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/index_shards_wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (

"github.com/blugelabs/bluge"
blugeindex "github.com/blugelabs/bluge/index"
"github.com/goccy/go-json"
"github.com/rs/zerolog/log"

"github.com/zinclabs/zinc/pkg/config"
"github.com/zinclabs/zinc/pkg/errors"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/wal"
"github.com/zinclabs/zinc/pkg/zutils"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

// MaxBatchSize used to limit memory
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"github.com/blugelabs/bluge"
"github.com/blugelabs/bluge/analysis"
"github.com/blugelabs/bluge/analysis/analyzer"
"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"

"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

func TestIndex_Index(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/loadindexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package core

import (
"github.com/goccy/go-json"
"github.com/rs/zerolog/log"

"github.com/zinclabs/zinc/pkg/errors"
Expand All @@ -25,6 +24,7 @@ import (
"github.com/zinclabs/zinc/pkg/upgrade"
zincanalysis "github.com/zinclabs/zinc/pkg/uquery/analysis"
"github.com/zinclabs/zinc/pkg/zutils/hash/rendezvous"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

func LoadZincIndexesFromMetadata(version string) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/search/v1/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package v1

import "github.com/goccy/go-json"
import "github.com/zinclabs/zinc/pkg/zutils/json"

func HandleSource(source *Source, data []byte) map[string]interface{} {
ret := make(map[string]interface{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/document/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
"time"

"github.com/gin-gonic/gin"
"github.com/goccy/go-json"
"github.com/rs/zerolog/log"

"github.com/zinclabs/zinc/pkg/config"
"github.com/zinclabs/zinc/pkg/core"
"github.com/zinclabs/zinc/pkg/ider"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

// Bulk accept multiple documents, first line index metadata, second line document
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/document/multi_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/goccy/go-json"
"github.com/rs/zerolog/log"

"github.com/zinclabs/zinc/pkg/config"
"github.com/zinclabs/zinc/pkg/core"
"github.com/zinclabs/zinc/pkg/ider"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

// Multi accept multiple line json documents
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/index/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"strings"
"testing"

"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"

"github.com/zinclabs/zinc/pkg/core"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
"github.com/zinclabs/zinc/test/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/index/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"net/http"
"testing"

"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"

"github.com/zinclabs/zinc/pkg/core"
"github.com/zinclabs/zinc/pkg/zutils/json"
"github.com/zinclabs/zinc/test/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/index/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"net/http"
"testing"

"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"

"github.com/zinclabs/zinc/pkg/core"
"github.com/zinclabs/zinc/pkg/zutils/json"
"github.com/zinclabs/zinc/test/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/index/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"net/http"
"testing"

"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"

"github.com/zinclabs/zinc/pkg/core"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
"github.com/zinclabs/zinc/test/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/index/refresh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"net/http"
"testing"

"github.com/goccy/go-json"
"github.com/stretchr/testify/assert"

"github.com/zinclabs/zinc/pkg/core"
"github.com/zinclabs/zinc/pkg/zutils/json"
"github.com/zinclabs/zinc/test/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/search/search_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
"strings"

"github.com/gin-gonic/gin"
"github.com/goccy/go-json"
"github.com/rs/zerolog/log"

"github.com/zinclabs/zinc/pkg/config"
"github.com/zinclabs/zinc/pkg/core"
"github.com/zinclabs/zinc/pkg/errors"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

// SearchDSL searches the index for the given http request from end user
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/elastic/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"bytes"
"sync"

"github.com/goccy/go-json"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

// Mappings holds the index mappings.
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"bytes"
"sync"

"github.com/goccy/go-json"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

type Mappings struct {
Expand Down
4 changes: 1 addition & 3 deletions pkg/metadata/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

package metadata

import (
"github.com/goccy/go-json"
)
import "github.com/zinclabs/zinc/pkg/zutils/json"

type alias struct{}

Expand Down
3 changes: 1 addition & 2 deletions pkg/metadata/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
package metadata

import (
"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/upgrade"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

type index struct{}
Expand Down
3 changes: 1 addition & 2 deletions pkg/metadata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
package metadata

import (
"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

type template struct{}
Expand Down
3 changes: 1 addition & 2 deletions pkg/metadata/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
package metadata

import (
"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

type user struct{}
Expand Down
2 changes: 2 additions & 0 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func Do(oldVersion string, index *meta.Index) error {
return err
}
return nil
case "0.2.7", "0.2.8", "0.2.9", "0.3.0", "0.3.1":
return nil
default:
return fmt.Errorf("unsupported upgrade from version: %s", oldVersion)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/upgrade/v026t027.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import (
"path"
"sort"

"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/config"
"github.com/zinclabs/zinc/pkg/ider"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

// UpgradeFromV026T027 upgrades from version v0.2.6
Expand Down
3 changes: 1 addition & 2 deletions pkg/uquery/fields/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import (
"strings"
"time"

"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/errors"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

func Request(v []interface{}) ([]*meta.Field, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import (
"fmt"

"github.com/blugelabs/bluge/analysis"
"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/errors"
"github.com/zinclabs/zinc/pkg/meta"
zincanalysis "github.com/zinclabs/zinc/pkg/uquery/analysis"
"github.com/zinclabs/zinc/pkg/uquery/mappings"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

func Request(data map[string]interface{}) (*meta.Index, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/mappings/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"strings"

"github.com/blugelabs/bluge/analysis"
"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/config"
"github.com/zinclabs/zinc/pkg/errors"
"github.com/zinclabs/zinc/pkg/meta"
zincanalysis "github.com/zinclabs/zinc/pkg/uquery/analysis"
"github.com/zinclabs/zinc/pkg/zutils"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

func Request(analyzers map[string]*analysis.Analyzer, data map[string]interface{}) (*meta.Mappings, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/uquery/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (

"github.com/blugelabs/bluge"
"github.com/blugelabs/bluge/analysis"
"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/errors"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

func Query(query interface{}, mappings *meta.Mappings, analyzers map[string]*analysis.Analyzer) (bluge.Query, error) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/uquery/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ package source
import (
"strings"

"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/errors"
"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

func Request(v interface{}) (*meta.Source, error) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/uquery/timerange/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ package timerange
import (
"strings"

"github.com/goccy/go-json"

"github.com/zinclabs/zinc/pkg/meta"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

func Query(query interface{}) (int64, int64) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/zutils/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"io"

"github.com/gin-gonic/gin"
"github.com/goccy/go-json"
"github.com/zinclabs/zinc/pkg/zutils/json"
)

func GinBindJSON(c *gin.Context, obj interface{}) error {
Expand Down
21 changes: 21 additions & 0 deletions pkg/zutils/json/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright 2022 Zinc Labs Inc. and Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package json

import "github.com/goccy/go-json"

var Marshal = json.Marshal
var Unmarshal = json.Unmarshal
Loading

0 comments on commit 5dba586

Please sign in to comment.