Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: Add Custom JSON Package with Build Tag Support for Sonic #1623

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8333e5c
tag optional sonic and allow full library conversion
Aug 20, 2024
c47137c
Add workflow and disallow arm and darwin usage
Aug 20, 2024
6e24f60
Add basic hotswap benchmark
Aug 20, 2024
b70b9e7
linter: fix
Aug 20, 2024
84dd409
use bash
Aug 20, 2024
711db77
linter: fix?
Aug 20, 2024
223f786
Fix whoopsie, add to make file, also add mention in features list.
Aug 20, 2024
9a72688
Merge branch 'master' into encoding_swap
Aug 24, 2024
2f69362
Merge branch 'master' into encoding_swap
Sep 2, 2024
79c85c9
Merge branch 'master' into encoding_swap
Sep 13, 2024
b4f0243
Merge branch 'master' into encoding_swap
Sep 13, 2024
417e0aa
Merge branch 'master' into encoding_swap
Sep 15, 2024
83f1d57
Merge branch 'master' into encoding_swap
Oct 2, 2024
f2d56cf
Merge branch 'master' into encoding_swap
Oct 10, 2024
7bd7cc4
Merge branch 'master' into encoding_swap
Oct 23, 2024
79ebfa1
Merge branch 'master' into encoding_swap
Nov 11, 2024
6b6fb5e
test enforcement
Nov 11, 2024
ac47cc6
actually read documentation see if this works
Nov 11, 2024
135e2b6
linter: fix
Nov 11, 2024
2d08549
Merge branch 'master' into encoding_swap
Nov 25, 2024
1a82764
Merge branch 'master' into encoding_swap
Jan 8, 2025
1ca8eaa
linter: fix
Jan 8, 2025
ab5fd01
sonic: bump tagged version
Jan 10, 2025
1697977
encoding/json: drop build tag arch and os filters
Jan 10, 2025
3905b62
encoding/json: consolidate tests
Jan 10, 2025
1c9f9c2
encoding/json: log build tag usage
Jan 10, 2025
4f8e487
Merge branch 'master' into encoding_swap
Jan 13, 2025
9cffc8f
rm superfluous builds
Jan 13, 2025
1b15e4c
glorious/nits: add template change and regen docs
Jan 28, 2025
a7ac15d
glorious/nits: update commentary on nolint directive
Jan 28, 2025
f23f3c3
glorious/nits: rm init func and log results in main.go
Jan 28, 2025
fba5316
Test to actually pull flag in
Jan 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,32 @@ jobs:
goarch: amd64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this line, would you consider a log on GCT start to say which one is enabled? Yes, you have build tags, but then it puts it in the logs of the application

Could add to the build tag files to call like json.Version() where its fmt.Println("hello my name is Sonic and I gotta go fast, okay?") as an example

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psql: true
skip_wrapper_tests: false
sonic: false
- os: ubuntu-latest
goarch: 386
psql: true
skip_wrapper_tests: true
sonic: false
- os: macos-latest
goarch: amd64
psql: true
skip_wrapper_tests: true
sonic: false
- os: macos-13 # beta
goarch: amd64
psql: true
skip_wrapper_tests: true
sonic: false
- os: windows-latest
goarch: amd64
psql: true
skip_wrapper_tests: true
sonic: false
- os: ubuntu-latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing which one is sonic in anyway from the build list.
image
Or is there two that use sonic (the last two ubuntu builds)? Am I blind? 🙈

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last one is a docker build so it only comes up with false true, but the matrix build above, seems to be the only one with sonic set to true, but in the logs, it doesn't seem to pull the bytedance package down. I am trying to fix that now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Unintended catch by you sir 🚀 but that should be good to go now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the docker build is ded, but otherwise, looks good

goarch: amd64
psql: true
skip_wrapper_tests: false
sonic: true

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -84,13 +94,20 @@ jobs:
echo "CGO_ENABLED=1" >> $GITHUB_ENV
shell: bash

- name: Set test flags
run: |
if [ "${{ matrix.sonic }}" = "true" ]; then
echo "TEST_FLAGS=-tags sonic" >> $GITHUB_ENV
fi
shell: bash

- name: Test
run: | # PGSERVICEFILE isn't supported by lib/pq and will cause a panic if set
unset PGSERVICEFILE
if [ "${{ matrix.goarch }}" = "386" ]; then
go test -coverprofile coverage.txt -covermode atomic ./...
go test $TEST_FLAGS -coverprofile coverage.txt -covermode atomic ./...
else
go test -race -coverprofile coverage.txt -covermode atomic ./...
go test $TEST_FLAGS -race -coverprofile coverage.txt -covermode atomic ./...
fi
shell: bash
env:
Expand Down Expand Up @@ -169,4 +186,4 @@ jobs:
cd web/
npm install
npm run lint
npm run build
npm run build
14 changes: 12 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ linters:
- copyloopvar
# - cyclop
- decorder
# - depguard
- depguard
- dogsled
# - dupl
- dupword
Expand Down Expand Up @@ -117,6 +117,17 @@ linters:
# - zerologlint

linters-settings:
depguard:
shazbert marked this conversation as resolved.
Show resolved Hide resolved
rules:
prevent_json_package_use:
list-mode: lax # allow unless explicitely denied
files:
- $all
allow:
- github.com/thrasher-corp/gocryptotrader/encoding/json
deny:
- pkg: encoding/json
desc: "Please use the custom JSON package github.com/thrasher-corp/gocryptotrader/encoding/json instead of encoding/json to allow sonic/json switching."
govet:
enable:
- shadow
Expand All @@ -141,7 +152,6 @@ linters-settings:
- float-compare
# We deliberately use Equal over Len to avoid spamming the contents of large Slices
- len

issues:
max-issues-per-linter: 0
max-same-issues: 0
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014-2024 The GoCryptoTrader Developers
Copyright (c) 2014-2025 The GoCryptoTrader Developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ endef
check-jq:
@printf "Checking if jq is installed... "
@command -v jq >/dev/null 2>&1 && { printf "OK\n"; } || { printf "FAILED. Please install jq to proceed.\n"; exit 1; }

.PHONY: sonic
sonic:
go build -tags=sonic ./...
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ However, we welcome pull requests for any exchange which does not match this cri
+ WebGUI (discontinued).
+ Exchange HTTP mock testing. See [mock](/exchanges/mock/README.md).
+ Exchange multichain deposits and withdrawals for specific exchanges. See [multichain transfer support](/docs/MULTICHAIN_TRANSFER_SUPPORT.md).
+ Sonic JSON Integration. Swap between the default Go 'encoding/json' package and the sonic library using go build tags for optimized JSON handling `-tags=sonic` or by using the make file `make sonic`

## Development Tracking

Expand Down Expand Up @@ -148,15 +149,15 @@ Binaries will be published once the codebase reaches a stable condition.

|User|Contribution Amount|
|--|--|
| [thrasher-](https://github.com/thrasher-) | 703 |
| [shazbert](https://github.com/shazbert) | 355 |
| [dependabot[bot]](https://github.com/apps/dependabot) | 331 |
| [thrasher-](https://github.com/thrasher-) | 704 |
| [shazbert](https://github.com/shazbert) | 356 |
| [dependabot[bot]](https://github.com/apps/dependabot) | 344 |
| [gloriousCode](https://github.com/gloriousCode) | 236 |
| [gbjk](https://github.com/gbjk) | 107 |
| [gbjk](https://github.com/gbjk) | 111 |
| [dependabot-preview[bot]](https://github.com/apps/dependabot-preview) | 88 |
| [xtda](https://github.com/xtda) | 47 |
| [lrascao](https://github.com/lrascao) | 27 |
| [Beadko](https://github.com/Beadko) | 17 |
| [Beadko](https://github.com/Beadko) | 18 |
| [Rots](https://github.com/Rots) | 15 |
| [vazha](https://github.com/vazha) | 15 |
| [ydm](https://github.com/ydm) | 15 |
Expand Down
2 changes: 1 addition & 1 deletion backtester/btcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"log"
"os"
Expand All @@ -13,6 +12,7 @@ import (

"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/gctrpc/auth"
"github.com/thrasher-corp/gocryptotrader/signaler"
"github.com/urfave/cli/v2"
Expand Down
2 changes: 1 addition & 1 deletion backtester/config/backtesterconfig.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package config

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

"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
gctconfig "github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
)

// ReadBacktesterConfigFromPath will take a config from a path
Expand Down
2 changes: 1 addition & 1 deletion backtester/config/batcktesterconfig_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package config

import (
"encoding/json"
"errors"
"path/filepath"
"testing"

"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
)

func TestLoadBacktesterConfig(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion backtester/config/strategyconfig.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"encoding/json"
"fmt"
"os"
"strings"
Expand All @@ -13,6 +12,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies/base"
gctcommon "github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/log"
)
Expand Down
2 changes: 1 addition & 1 deletion backtester/config/strategyconfig_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"encoding/json"
"errors"
"os"
"path/filepath"
Expand All @@ -17,6 +16,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/drivers"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
Expand Down
2 changes: 1 addition & 1 deletion backtester/config/strategyconfigbuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bufio"
"encoding/json"
"errors"
"fmt"
"log"
Expand All @@ -23,6 +22,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/database"
dbPSQL "github.com/thrasher-corp/gocryptotrader/database/drivers/postgres"
dbsqlite3 "github.com/thrasher-corp/gocryptotrader/database/drivers/sqlite3"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
gctkline "github.com/thrasher-corp/gocryptotrader/exchanges/kline"
)
Expand Down
2 changes: 1 addition & 1 deletion backtester/eventhandlers/statistics/statistics.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package statistics

import (
"encoding/json"
"fmt"
"time"

Expand All @@ -17,6 +16,7 @@ import (
gctcommon "github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/key"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/log"
)

Expand Down
2 changes: 1 addition & 1 deletion backtester/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"net/http"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/backtester/plugins/strategies"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/engine"
"github.com/thrasher-corp/gocryptotrader/log"
"github.com/thrasher-corp/gocryptotrader/signaler"
Expand Down
2 changes: 1 addition & 1 deletion cmd/apichecker/apicheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
Expand All @@ -18,6 +17,7 @@ import (

"github.com/thrasher-corp/gocryptotrader/common"
gctfile "github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/log"
Expand Down
2 changes: 1 addition & 1 deletion cmd/apichecker/apicheck_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"encoding/json"
"os"
"reflect"
"testing"

gctfile "github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/log"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/config_builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

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

"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/engine"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/documentation/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
Expand All @@ -17,6 +16,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
Expand Down
1 change: 1 addition & 0 deletions cmd/documentation/root_templates/root_readme.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ However, we welcome pull requests for any exchange which does not match this cri
+ WebGUI (discontinued).
+ Exchange HTTP mock testing. See [mock](/exchanges/mock/README.md).
+ Exchange multichain deposits and withdrawals for specific exchanges. See [multichain transfer support](/docs/MULTICHAIN_TRANSFER_SUPPORT.md).
+ Sonic JSON Integration. Swap between the default Go 'encoding/json' package and the sonic library using go build tags for optimized JSON handling `-tags=sonic` or by using the make file `make sonic`

## Development Tracking

Expand Down
4 changes: 2 additions & 2 deletions cmd/exchange_wrapper_issues/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
Expand All @@ -19,6 +18,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/engine"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
Expand Down Expand Up @@ -1028,7 +1028,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
}

func jsonifyInterface(params []interface{}) json.RawMessage {
response, _ := json.MarshalIndent(params, "", " ") //nolint:errchkjson // TODO: ignore this for now
response, _ := json.MarshalIndent(params, "", " ")
return response
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/exchange_wrapper_issues/types.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package main

import (
"encoding/json"

"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/gctcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"log"
"os"
Expand All @@ -12,6 +11,7 @@ import (

"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/core"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/gctrpc/auth"
"github.com/thrasher-corp/gocryptotrader/signaler"
Expand Down
Loading
Loading