Skip to content

Commit

Permalink
Merge pull request #29 from nkryuchkov/feature/jsoniter
Browse files Browse the repository at this point in the history
Use jsoniter instead of encoding/json
  • Loading branch information
jdknives authored Nov 10, 2020
2 parents a08c07b + 52a12d1 commit f50a251
Show file tree
Hide file tree
Showing 177 changed files with 11,847 additions and 7,894 deletions.
4 changes: 3 additions & 1 deletion cmd/dmsg-discovery/internal/api/api.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package api

import (
"encoding/json"
"net"
"net/http"
"time"

"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/skycoin/skycoin/src/util/logging"

Expand All @@ -19,6 +19,8 @@ import (

var log = logging.MustGetLogger("dmsg-discovery")

var json = jsoniter.ConfigFastest

const maxGetAvailableServersResult = 512

// API represents the api of the dmsg-discovery service`
Expand Down
1 change: 0 additions & 1 deletion cmd/dmsg-discovery/internal/api/entries_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
Expand Down
1 change: 0 additions & 1 deletion cmd/dmsg-discovery/internal/api/error_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package api

import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"sort"
Expand Down
4 changes: 3 additions & 1 deletion cmd/dmsg-discovery/internal/store/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package store

import (
"context"
"encoding/json"
"time"

"github.com/go-redis/redis"
jsoniter "github.com/json-iterator/go"

"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/dmsg/disc"
)

var json = jsoniter.ConfigFastest

type redisStore struct {
client *redis.Client
timeout time.Duration
Expand Down
1 change: 0 additions & 1 deletion cmd/dmsg-discovery/internal/store/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package store

import (
"context"
"encoding/json"
"sync"
"time"

Expand Down
4 changes: 3 additions & 1 deletion cmd/dmsgpty-host/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package commands
import (
"bytes"
"context"
"encoding/json"
"fmt"
stdlog "log"
"net"
"os"
"sync"

jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cast"
Expand All @@ -29,6 +29,8 @@ const defaultEnvPrefix = "DMSGPTY"

var log = logging.MustGetLogger("dmsgpty-host:init")

var json = jsoniter.ConfigFastest

// variables
var (
// persistent flags (with viper references)
Expand Down
6 changes: 4 additions & 2 deletions cmdutil/service_flags.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmdutil

import (
"encoding/json"
"errors"
"fmt"
"io"
Expand All @@ -14,6 +13,7 @@ import (

"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/skycoin/src/util/logging"
Expand All @@ -32,6 +32,8 @@ var (
ErrInvalidSyslogNet = errors.New("network type is unsupported for syslog")
)

var json = jsoniter.ConfigFastest

const (
stdinConfig = "stdin"
)
Expand Down Expand Up @@ -179,7 +181,7 @@ func (sf *ServiceFlags) ParseConfig(args []string, checkArgs bool, v interface{}
return fmt.Errorf("failed to decode config file: %w", err)
}

j, err := json.MarshalIndent(v, "", "\t")
j, err := json.MarshalIndent(v, "", " ")
if err != nil {
panic(err) // should not happen
}
Expand Down
4 changes: 3 additions & 1 deletion disc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ package disc
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"sync"
"time"

jsoniter "github.com/json-iterator/go"
"github.com/skycoin/skycoin/src/util/logging"

"github.com/skycoin/dmsg/cipher"
)

var log = logging.MustGetLogger("disc")

var json = jsoniter.ConfigFastest

// APIClient implements dmsg discovery API client.
type APIClient interface {
Entry(context.Context, cipher.PubKey) (*Entry, error)
Expand Down
1 change: 0 additions & 1 deletion disc/entry.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package disc

import (
"encoding/json"
"errors"
"fmt"
"strings"
Expand Down
4 changes: 3 additions & 1 deletion dmsgget/dmsgget.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dmsgget

import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
Expand All @@ -12,6 +11,7 @@ import (
"path/filepath"
"time"

jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/skycoin/skycoin/src/util/logging"

Expand All @@ -21,6 +21,8 @@ import (
"github.com/skycoin/dmsg/dmsghttp"
)

var json = jsoniter.ConfigFastest

// DmsgGet contains the logic for dmsgget (wget over dmsg).
type DmsgGet struct {
startF startupFlags
Expand Down
5 changes: 4 additions & 1 deletion dmsgpty/whitelist.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package dmsgpty

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"sync"

jsoniter "github.com/json-iterator/go"

"github.com/skycoin/dmsg/cipher"
)

var json = jsoniter.ConfigFastest

// Whitelist represents a whitelist of public keys.
type Whitelist interface {
Get(pk cipher.PubKey) (bool, error)
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ require (
github.com/creack/pty v1.1.9
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-redis/redis v6.15.6+incompatible
github.com/gorilla/handlers v1.4.2
github.com/gorilla/handlers v1.4.2 // indirect
github.com/json-iterator/go v1.1.10
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/kz/discordrus v1.2.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
Expand Down Expand Up @@ -118,8 +120,10 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down
4 changes: 3 additions & 1 deletion httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package httputil

import (
"context"
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/go-chi/chi/middleware"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/skycoin/skycoin/src/util/logging"
)

var json = jsoniter.ConfigFastest

var log = logging.MustGetLogger("httputil")

// WriteJSON writes a json object on a http.ResponseWriter with the given code,
Expand Down
67 changes: 0 additions & 67 deletions vendor/github.com/go-chi/httplog/README.md

This file was deleted.

67 changes: 0 additions & 67 deletions vendor/github.com/go-chi/httplog/config.go

This file was deleted.

Loading

0 comments on commit f50a251

Please sign in to comment.