Skip to content

Commit

Permalink
apply type
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokisan committed Apr 11, 2023
1 parent 3aa742e commit 5f9611e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions v5_ws_public.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ type V5WebsocketPublicTopic string

const (
// V5WebsocketPublicTopicOrderBook :
V5WebsocketPublicTopicOrderBook = "orderbook"
V5WebsocketPublicTopicOrderBook = V5WebsocketPublicTopic("orderbook")

// V5WebsocketPublicTopicKline :
V5WebsocketPublicTopicKline = "kline"
V5WebsocketPublicTopicKline = V5WebsocketPublicTopic("kline")

// V5WebsocketPublicTopicTicker :
V5WebsocketPublicTopicTicker = "tickers"
V5WebsocketPublicTopicTicker = V5WebsocketPublicTopic("tickers")
)

func (t V5WebsocketPublicTopic) String() string {
return string(t)
}

// judgeTopic :
func (s *V5WebsocketPublicService) judgeTopic(respBody []byte) (V5WebsocketPublicTopic, error) {
parsedData := map[string]interface{}{}
Expand All @@ -81,11 +85,11 @@ func (s *V5WebsocketPublicService) judgeTopic(respBody []byte) (V5WebsocketPubli
}
if topic, ok := parsedData["topic"].(string); ok {
switch {
case strings.Contains(topic, "orderbook"):
case strings.Contains(topic, V5WebsocketPublicTopicOrderBook.String()):
return V5WebsocketPublicTopicOrderBook, nil
case strings.Contains(topic, "kline"):
case strings.Contains(topic, V5WebsocketPublicTopicKline.String()):
return V5WebsocketPublicTopicKline, nil
case strings.Contains(topic, "tickers"):
case strings.Contains(topic, V5WebsocketPublicTopicTicker.String()):
return V5WebsocketPublicTopicTicker, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion v5_ws_public_kline.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type V5WebsocketPublicKlineData struct {
func (r *V5WebsocketPublicKlineResponse) Key() V5WebsocketPublicKlineParamKey {
topic := r.Topic
arr := strings.Split(topic, ".")
if arr[0] != V5WebsocketPublicTopicKline || len(arr) != 3 {
if arr[0] != V5WebsocketPublicTopicKline.String() || len(arr) != 3 {
return V5WebsocketPublicKlineParamKey{}
}

Expand Down
2 changes: 1 addition & 1 deletion v5_ws_public_orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (b *V5WebsocketPublicOrderBookAsks) UnmarshalJSON(data []byte) error {
func (r *V5WebsocketPublicOrderBookResponse) Key() V5WebsocketPublicOrderBookParamKey {
topic := r.Topic
arr := strings.Split(topic, ".")
if arr[0] != V5WebsocketPublicTopicOrderBook || len(arr) != 3 {
if arr[0] != V5WebsocketPublicTopicOrderBook.String() || len(arr) != 3 {
return V5WebsocketPublicOrderBookParamKey{}
}
depth, err := strconv.Atoi(arr[1])
Expand Down
2 changes: 1 addition & 1 deletion v5_ws_public_ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type V5WebsocketPublicTickerSpotResult struct {
func (r *V5WebsocketPublicTickerResponse) Key() V5WebsocketPublicTickerParamKey {
topic := r.Topic
arr := strings.Split(topic, ".")
if arr[0] != V5WebsocketPublicTopicTicker || len(arr) != 2 {
if arr[0] != V5WebsocketPublicTopicTicker.String() || len(arr) != 2 {
return V5WebsocketPublicTickerParamKey{}
}

Expand Down

0 comments on commit 5f9611e

Please sign in to comment.