mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 23:16:53 +00:00
Config: Refactor version packages (#1887)
* Config: Move config versions to separate pacakges * Config: Move version tests to blackbox texts * Config: Protect registerVersion from overflow * Config: Protect against version already registered
This commit is contained in:
35
config/versions/v3/v3.go
Normal file
35
config/versions/v3/v3.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/buger/jsonparser"
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
)
|
||||
|
||||
// Version is an ExchangeVersion to remove the publishPeriod from the exchange's orderbook config
|
||||
type Version struct{}
|
||||
|
||||
// Exchanges returns all exchanges: "*"
|
||||
func (*Version) Exchanges() []string { return []string{"*"} }
|
||||
|
||||
// UpgradeExchange will remove the publishPeriod from the exchange's orderbook config
|
||||
func (*Version) UpgradeExchange(_ context.Context, e []byte) ([]byte, error) {
|
||||
e = jsonparser.Delete(e, "orderbook", "publishPeriod")
|
||||
return e, nil
|
||||
}
|
||||
|
||||
const defaultOrderbookPublishPeriod = time.Second * 10
|
||||
|
||||
// DowngradeExchange will downgrade the exchange's config by setting the default orderbook publish period
|
||||
func (*Version) DowngradeExchange(_ context.Context, e []byte) ([]byte, error) {
|
||||
if _, _, _, err := jsonparser.Get(e, "orderbook"); err != nil {
|
||||
return e, nil //nolint:nilerr // No error, just return the original config
|
||||
}
|
||||
out, err := json.Marshal(defaultOrderbookPublishPeriod)
|
||||
if err != nil {
|
||||
return e, err
|
||||
}
|
||||
return jsonparser.Set(e, out, "orderbook", "publishPeriod")
|
||||
}
|
||||
Reference in New Issue
Block a user