Extracted dict to Fetcher

This commit is contained in:
Artyom Belousov 2021-02-07 15:18:46 +03:00
parent 1f69282c73
commit 4da8e94bcc
7 changed files with 22 additions and 19 deletions

View file

@ -2,10 +2,8 @@ package vk
import (
"errors"
"io"
"log"
"net/http"
"os"
"strings"
"github.com/gin-gonic/gin"
@ -27,7 +25,7 @@ type CardInfoFetcher interface {
GetPrices(name string) ([]cardsinfo.CardPrice, error)
FormatCardPrices(name string, prices []cardsinfo.CardPrice) string
GetNameByCardId(set string, number string) string
GetOriginalName(name string, dict io.Reader) string
GetOriginalName(name string) string
}
type CardCache interface {
@ -119,8 +117,7 @@ func (h *Handler) getCardNameByCommand(command string) (string, error) {
number := split[2]
name = h.InfoFetcher.GetNameByCardId(set, number)
default:
dict, _ := os.Open(h.DictPath)
name = h.InfoFetcher.GetOriginalName(command, dict)
name = h.InfoFetcher.GetOriginalName(command)
}
return name, nil
}

View file

@ -3,7 +3,6 @@ package vk
import (
"errors"
"gitlab.com/flygrounder/go-mtg-vk/internal/cardsinfo"
"io"
)
type testInfoFetcher struct{}
@ -23,7 +22,7 @@ func (t *testInfoFetcher) GetNameByCardId(_ string, _ string) string {
return "good"
}
func (t *testInfoFetcher) GetOriginalName(name string, _ io.Reader) string {
func (t *testInfoFetcher) GetOriginalName(name string) string {
if name == "good" || name == "bad" || name == "uncached" {
return name
}