Skip to content

Commit

Permalink
use jsoniter instead of encoding/json
Browse files Browse the repository at this point in the history
  • Loading branch information
Sora233 committed Aug 16, 2021
1 parent 787abaa commit 470791c
Show file tree
Hide file tree
Showing 21 changed files with 28 additions and 33 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4
github.com/golang/protobuf v1.5.2
github.com/hashicorp/golang-lru v0.5.4
github.com/json-iterator/go v1.1.10
github.com/jupp0r/go-priority-queue v0.0.0-20160601094913-ab1073853bde
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/modern-go/gls v0.0.0-20190610040709-84558782a674
Expand Down
4 changes: 3 additions & 1 deletion image_pool/lolicon_pool/persist.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package lolicon_pool

import (
"encoding/json"
localdb "github.com/Sora233/DDBOT/lsp/buntdb"
jsoniter "github.com/json-iterator/go"
"github.com/tidwall/buntdb"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

func (pool *LoliconPool) load() {
pool.cond.L.Lock()
defer pool.cond.L.Unlock()
Expand Down
3 changes: 3 additions & 0 deletions lsp/bilibili/bilibili.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/Sora233/DDBOT/requests"
jsoniter "github.com/json-iterator/go"
"strconv"
"strings"
"sync"
Expand All @@ -19,6 +20,8 @@ const (
PassportHost = "https://passport.bilibili.com"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

var BasePath = map[string]string{
PathRoomInit: BaseLiveHost,
PathXSpaceAccInfo: BaseHost,
Expand Down
1 change: 0 additions & 1 deletion lsp/bilibili/card_extension.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bilibili

import (
"encoding/json"
"errors"
)

Expand Down
1 change: 0 additions & 1 deletion lsp/bilibili/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bilibili
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"errors"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Sora233/DDBOT/concern"
Expand Down
1 change: 0 additions & 1 deletion lsp/bilibili/stateManager.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bilibili

import (
"encoding/json"
"errors"
localdb "github.com/Sora233/DDBOT/lsp/buntdb"
"github.com/Sora233/DDBOT/lsp/concern_manager"
Expand Down
1 change: 0 additions & 1 deletion lsp/concern_manager/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package concern_manager

import (
"encoding/json"
"strings"
)

Expand Down
1 change: 0 additions & 1 deletion lsp/concern_manager/config_filter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package concern_manager

import (
"encoding/json"
"errors"
)

Expand Down
2 changes: 2 additions & 0 deletions lsp/concern_manager/stateManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
localdb "github.com/Sora233/DDBOT/lsp/buntdb"
localutils "github.com/Sora233/DDBOT/utils"
"github.com/Sora233/sliceutil"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"github.com/tidwall/buntdb"
"strings"
"sync"
"time"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary
var logger = utils.GetModuleLogger("concern_manager")
var ErrEmitQNotInit = errors.New("emit queue not enabled")

Expand Down
1 change: 0 additions & 1 deletion lsp/douyu/betard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package douyu

import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/Sora233/DDBOT/proxy_pool"
Expand Down
7 changes: 6 additions & 1 deletion lsp/douyu/douyu.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package douyu

import "strconv"
import (
jsoniter "github.com/json-iterator/go"
"strconv"
)

const (
Site = "douyu"
Host = "https://www.douyu.com"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

func DouyuPath(path string) string {
return Host + path
}
Expand Down
1 change: 0 additions & 1 deletion lsp/douyu/model.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package douyu

import (
"encoding/json"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Sora233/DDBOT/concern"
"github.com/Sora233/DDBOT/proxy_pool"
Expand Down
1 change: 0 additions & 1 deletion lsp/douyu/stateManager.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package douyu

import (
"encoding/json"
"errors"
localdb "github.com/Sora233/DDBOT/lsp/buntdb"
"github.com/Sora233/DDBOT/lsp/concern_manager"
Expand Down
2 changes: 2 additions & 0 deletions lsp/huya/concern.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"github.com/Sora233/DDBOT/concern"
"github.com/Sora233/DDBOT/lsp/concern_manager"
localutils "github.com/Sora233/DDBOT/utils"
jsoniter "github.com/json-iterator/go"
"reflect"
"runtime"
"sync"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary
var logger = utils.GetModuleLogger("huya-concern")

type EventType int64
Expand Down
1 change: 0 additions & 1 deletion lsp/huya/model.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package huya

import (
"encoding/json"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Sora233/DDBOT/concern"
"github.com/Sora233/DDBOT/proxy_pool"
Expand Down
1 change: 0 additions & 1 deletion lsp/huya/stateManager.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package huya

import (
"encoding/json"
"errors"
localdb "github.com/Sora233/DDBOT/lsp/buntdb"
"github.com/Sora233/DDBOT/lsp/concern_manager"
Expand Down
5 changes: 5 additions & 0 deletions lsp/stateManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ type StateManager struct {
KeySet
}

//
//func (s *StateManager) SaveGroupMessage(msg *message.GroupMessage) error {
//
//}

func (s *StateManager) SaveMessageImageUrl(groupCode int64, messageID int32, msgs []message.IMessageElement) error {
imgs := utils.MessageFilter(msgs, func(e message.IMessageElement) bool {
return e.Type() == message.Image
Expand Down
1 change: 0 additions & 1 deletion lsp/youtube/model.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package youtube

import (
"encoding/json"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Sora233/DDBOT/concern"
"github.com/Sora233/DDBOT/proxy_pool"
Expand Down
1 change: 0 additions & 1 deletion lsp/youtube/stateManager.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package youtube

import (
"encoding/json"
localdb "github.com/Sora233/DDBOT/lsp/buntdb"
"github.com/Sora233/DDBOT/lsp/concern_manager"
"github.com/tidwall/buntdb"
Expand Down
4 changes: 4 additions & 0 deletions lsp/youtube/youtube.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package youtube

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

const Site = "youtube"
const VideoView = "https://www.youtube.com/watch?v="

var json = jsoniter.ConfigCompatibleWithStandardLibrary

func VideoViewUrl(videoId string) string {
return VideoView + videoId
}
21 changes: 2 additions & 19 deletions utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package utils

import (
"encoding/json"
"errors"
"fmt"
"github.com/Logiase/MiraiGo-Template/bot"
"github.com/Mrs4s/MiraiGo/message"
"github.com/Sora233/requests"
"github.com/davecgh/go-spew/spew"
jsoniter "github.com/json-iterator/go"
"github.com/sirupsen/logrus"
"net/url"
"os"
Expand All @@ -20,6 +20,7 @@ import (
"time"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary
var ErrGoCvNotSetUp = errors.New("gocv not setup")

func FilePathWalkDir(root string) ([]string, error) {
Expand Down Expand Up @@ -234,24 +235,6 @@ func MsgToString(elements []message.IMessageElement) (res string) {
return
}

// CompareId 用_id的类型信息去转换number类型,并尝试比较
func CompareId(number json.Number, _id interface{}) bool {
idType := reflect.TypeOf(_id)
switch idType.Kind() {
case reflect.Int64:
jid, err := number.Int64()
if err != nil {
panic(err)
}
return jid == _id.(int64)
case reflect.String:
jid := number.String()
return jid == _id.(string)
default:
return false
}
}

func Switch2Bool(_s string) bool {
return _s == "on"
}
Expand Down

0 comments on commit 470791c

Please sign in to comment.