Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions src/TibiaCharactersCharacter.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type CharacterResponse struct {
const Br = 0x202

// TibiaCharactersCharacter func
func TibiaCharactersCharacterImpl(BoxContentHTML string) (*CharacterResponse, error) {
func TibiaCharactersCharacterImpl(BoxContentHTML string) (CharacterResponse, error) {
var (
// local strings used in this function
localDivQueryString = ".TableContentContainer tr"
Expand All @@ -144,7 +144,7 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (*CharacterResponse, er
// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
return nil, fmt.Errorf("TibiaCharactersCharacterImpl failed at goquery.NewDocumentFromReader, err: %s", err)
return CharacterResponse{}, fmt.Errorf("TibiaCharactersCharacterImpl failed at goquery.NewDocumentFromReader, err: %s", err)
}

// Running query on every .TableContainer
Expand Down Expand Up @@ -612,9 +612,9 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (*CharacterResponse, er
// Search for errors
switch {
case characterNotFound:
return nil, validation.ErrorCharacterNotFound
return CharacterResponse{}, validation.ErrorCharacterNotFound
case insideError != nil:
return nil, insideError
return CharacterResponse{}, insideError
case reflect.DeepEqual(charData, Character{}):
// There are some rare cases where a character name would
// bug out tibia.com (tíbia, for example) and then we would't
Expand All @@ -624,12 +624,12 @@ func TibiaCharactersCharacterImpl(BoxContentHTML string) (*CharacterResponse, er
//
// Validating those names would also be a pain because of old
// tibian names such as Kolskägg, which for whatever reason is valid
return nil, validation.ErrorCharacterNotFound
return CharacterResponse{}, validation.ErrorCharacterNotFound
}

//
// Build the data-blob
return &CharacterResponse{
return CharacterResponse{
charData,
Information{
APIDetails: TibiaDataAPIDetails,
Expand Down
10 changes: 5 additions & 5 deletions src/TibiaCreaturesCreature.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ var (
CreatureLootRegex = regexp.MustCompile(`.*yield (.*) experience.*carry (.*)with them.`)
)

func TibiaCreaturesCreatureImpl(race string, BoxContentHTML string) (*CreatureResponse, error) {
func TibiaCreaturesCreatureImpl(race string, BoxContentHTML string) (CreatureResponse, error) {
// local strings used in this function
var localDamageString = " damage"

// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
return nil, fmt.Errorf("[error] TibiaCreaturesCreatureImp failed at goquery.NewDocumentFromReader, error: %s", err)
return CreatureResponse{}, fmt.Errorf("[error] TibiaCreaturesCreatureImp failed at goquery.NewDocumentFromReader, error: %s", err)
}

// Getting data
InnerTableContainerTMP1, err := ReaderHTML.Find(".BoxContent div").First().NextAll().Html()
if err != nil {
return nil, fmt.Errorf("[error] TibiaCreaturesCreatureImp failed at ReaderHTML.Find, error: %s", err)
return CreatureResponse{}, fmt.Errorf("[error] TibiaCreaturesCreatureImp failed at ReaderHTML.Find, error: %s", err)
}

// Regex to get data
Expand Down Expand Up @@ -162,11 +162,11 @@ func TibiaCreaturesCreatureImpl(race string, BoxContentHTML string) (*CreatureRe
}
} else {
log.Printf("[warning] TibiaCreaturesCreatureImpl called on invalid creature")
return nil, validation.ErrorCreatureNotFound
return CreatureResponse{}, validation.ErrorCreatureNotFound
}

// Build the data-blob
return &CreatureResponse{
return CreatureResponse{
Creature{
Name: CreatureName,
Race: race,
Expand Down
10 changes: 5 additions & 5 deletions src/TibiaCreaturesOverview.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ var (
CreatureInformationRegex = regexp.MustCompile(`.*race=(.*)"><img src="(.*)" border.*div>(.*)<\/div>`)
)

func TibiaCreaturesOverviewImpl(BoxContentHTML string) (*CreaturesOverviewResponse, error) {
func TibiaCreaturesOverviewImpl(BoxContentHTML string) (CreaturesOverviewResponse, error) {
var (
BoostedCreatureName, BoostedCreatureRace, BoostedCreatureImage string
)

// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
return nil, fmt.Errorf("[error] TibiaCreaturesOverviewImpl failed at goquery.NewDocumentFromReader, err: %s", err)
return CreaturesOverviewResponse{}, fmt.Errorf("[error] TibiaCreaturesOverviewImpl failed at goquery.NewDocumentFromReader, err: %s", err)
}

// Getting data from div.InnerTableContainer and then first p
InnerTableContainerTMPB, err := ReaderHTML.Find(".InnerTableContainer p").First().Html()
if err != nil {
return nil, fmt.Errorf("[error] TibiaCreaturesOverviewImpl failed at ReaderHTML.Find, err: %s", err)
return CreaturesOverviewResponse{}, fmt.Errorf("[error] TibiaCreaturesOverviewImpl failed at ReaderHTML.Find, err: %s", err)
}

// Regex to get data for name and race param for boosted creature
Expand Down Expand Up @@ -110,11 +110,11 @@ func TibiaCreaturesOverviewImpl(BoxContentHTML string) (*CreaturesOverviewRespon
})

if insideError != nil {
return nil, insideError
return CreaturesOverviewResponse{}, insideError
}

// Build the data-blob
return &CreaturesOverviewResponse{
return CreaturesOverviewResponse{
CreaturesContainer{
Boosted: OverviewCreature{
Name: TibiaDataSanitizeEscapedString(BoostedCreatureName),
Expand Down
8 changes: 4 additions & 4 deletions src/TibiaFansites.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ var (
FansiteAnchorRegex = regexp.MustCompile(`.*src="(.*)" alt=".*`)
)

func TibiaFansitesImpl(BoxContentHTML string) (*FansitesResponse, error) {
func TibiaFansitesImpl(BoxContentHTML string) (FansitesResponse, error) {
// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
return nil, fmt.Errorf("[error] TibiaFansitesImpl failed at goquery.NewDocumentFromReader, err: %s", err)
return FansitesResponse{}, fmt.Errorf("[error] TibiaFansitesImpl failed at goquery.NewDocumentFromReader, err: %s", err)
}

// Creating empty PromotedFansitesData and SupportedFansitesData var
Expand All @@ -77,7 +77,7 @@ func TibiaFansitesImpl(BoxContentHTML string) (*FansitesResponse, error) {
for _, FansiteType := range FansiteTypes {
fansites, err := makeFansiteRequest(FansiteType, ReaderHTML)
if err != nil {
return nil, fmt.Errorf("[error] TibiaFansitesImpl failed at makeFansiteRequest, type: %s, err: %s", FansiteType, err)
return FansitesResponse{}, fmt.Errorf("[error] TibiaFansitesImpl failed at makeFansiteRequest, type: %s, err: %s", FansiteType, err)
}

switch FansiteType {
Expand All @@ -89,7 +89,7 @@ func TibiaFansitesImpl(BoxContentHTML string) (*FansitesResponse, error) {
}

// Build the data-blob
return &FansitesResponse{
return FansitesResponse{
Fansites{
PromotedFansites: PromotedFansitesData,
SupportedFansites: SupportedFansitesData,
Expand Down
16 changes: 8 additions & 8 deletions src/TibiaGuildsGuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var (
GuildMemberInvitesInformationRegex = regexp.MustCompile(`<td><a.*">(.*)<\/a><\/td><td>(.*)<\/td>`)
)

func TibiaGuildsGuildImpl(guild string, BoxContentHTML string) (*GuildResponse, error) {
func TibiaGuildsGuildImpl(guild string, BoxContentHTML string) (GuildResponse, error) {
// Creating empty vars
var (
MembersData []GuildMember
Expand All @@ -92,22 +92,22 @@ func TibiaGuildsGuildImpl(guild string, BoxContentHTML string) (*GuildResponse,
// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
return nil, fmt.Errorf("[error] TibiaGuildsGuildImpl failed at goquery.NewDocumentFromReader, err: %s", err)
return GuildResponse{}, fmt.Errorf("[error] TibiaGuildsGuildImpl failed at goquery.NewDocumentFromReader, err: %s", err)
}

guildName, err := ReaderHTML.Find("h1").First().Html()
if err != nil {
return nil, fmt.Errorf("[error] TibiaGuildsGuildImpl failed at ReaderHTML.Find, err: %s", err)
return GuildResponse{}, fmt.Errorf("[error] TibiaGuildsGuildImpl failed at ReaderHTML.Find, err: %s", err)
}

if guildName == "" {
return nil, validation.ErrorGuildNotFound
return GuildResponse{}, validation.ErrorGuildNotFound
}

// Getting data from div.InnerTableContainer and then first p
InnerTableContainerTMPA, err := ReaderHTML.Find(".BoxContent table").Html()
if err != nil {
return nil, fmt.Errorf("[error] TibiaGuildsGuildImpl failed at InnerTableContainerTMPA ReaderHTML.Find, err: %s", err)
return GuildResponse{}, fmt.Errorf("[error] TibiaGuildsGuildImpl failed at InnerTableContainerTMPA ReaderHTML.Find, err: %s", err)
}

subma1b := GuildLogoRegex.FindAllStringSubmatch(InnerTableContainerTMPA, -1)
Expand All @@ -119,7 +119,7 @@ func TibiaGuildsGuildImpl(guild string, BoxContentHTML string) (*GuildResponse,
// Getting data from div.InnerTableContainer and then first p
InnerTableContainerTMPB, err := ReaderHTML.Find("#GuildInformationContainer").Html()
if err != nil {
return nil, fmt.Errorf("[error] TibiaGuildsGuildImpl failed at InnerTableContainerTMPB ReaderHTML.Find, err: %s", err)
return GuildResponse{}, fmt.Errorf("[error] TibiaGuildsGuildImpl failed at InnerTableContainerTMPB ReaderHTML.Find, err: %s", err)
}

for _, line := range strings.Split(strings.TrimSuffix(InnerTableContainerTMPB, "\n"), "\n") {
Expand Down Expand Up @@ -253,12 +253,12 @@ func TibiaGuildsGuildImpl(guild string, BoxContentHTML string) (*GuildResponse,
})

if insideError != nil {
return nil, insideError
return GuildResponse{}, insideError
}

//
// Build the data-blob
return &GuildResponse{
return GuildResponse{
Guild{
Name: guildName,
World: GuildWorld,
Expand Down
6 changes: 3 additions & 3 deletions src/TibiaGuildsOverview.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type GuildsOverviewResponse struct {
Information Information `json:"information"`
}

func TibiaGuildsOverviewImpl(world string, BoxContentHTML string) (*GuildsOverviewResponse, error) {
func TibiaGuildsOverviewImpl(world string, BoxContentHTML string) (GuildsOverviewResponse, error) {
// Creating empty vars
var (
ActiveGuilds, FormationGuilds []OverviewGuild
Expand All @@ -38,7 +38,7 @@ func TibiaGuildsOverviewImpl(world string, BoxContentHTML string) (*GuildsOvervi
// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
return nil, fmt.Errorf("[error] TibiaGuildsOverviewImpl failed at goquery.NewDocumentFromReader, err: %s", err)
return GuildsOverviewResponse{}, fmt.Errorf("[error] TibiaGuildsOverviewImpl failed at goquery.NewDocumentFromReader, err: %s", err)
}

// Running query over each div
Expand Down Expand Up @@ -87,7 +87,7 @@ func TibiaGuildsOverviewImpl(world string, BoxContentHTML string) (*GuildsOvervi

//
// Build the data-blob
return &GuildsOverviewResponse{
return GuildsOverviewResponse{
OverviewGuilds{
World: world,
Active: ActiveGuilds,
Expand Down
10 changes: 5 additions & 5 deletions src/TibiaHighscores.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ var (
SixColumnRegex = regexp.MustCompile(`<td>(.*)<\/td><td.*">(.*)<\/a><\/td><td.*">(.*)<\/td><td>(.*)<\/td><td.*>(.*)<\/td><td.*>(.*)<\/td>`)
)

func TibiaHighscoresImpl(world string, category validation.HighscoreCategory, vocationName string, currentPage int, BoxContentHTML string) (*HighscoresResponse, error) {
func TibiaHighscoresImpl(world string, category validation.HighscoreCategory, vocationName string, currentPage int, BoxContentHTML string) (HighscoresResponse, error) {
// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
return nil, fmt.Errorf("[error] TibiaHighscoresImpl failed at goquery.NewDocumentFromReader, err: %s", err)
return HighscoresResponse{}, fmt.Errorf("[error] TibiaHighscoresImpl failed at goquery.NewDocumentFromReader, err: %s", err)
}

// Creating empty HighscoreData var
Expand All @@ -81,7 +81,7 @@ func TibiaHighscoresImpl(world string, category validation.HighscoreCategory, vo
}

if currentPage > HighscoreTotalPages {
return nil, validation.ErrorHighscorePageTooBig
return HighscoresResponse{}, validation.ErrorHighscorePageTooBig
}

var insideError error
Expand Down Expand Up @@ -156,12 +156,12 @@ func TibiaHighscoresImpl(world string, category validation.HighscoreCategory, vo
categoryString, _ := category.String()

if insideError != nil {
return nil, insideError
return HighscoresResponse{}, insideError
}

//
// Build the data-blob
return &HighscoresResponse{
return HighscoresResponse{
Highscores{
World: cases.Title(language.English).String(world),
Category: categoryString,
Expand Down
10 changes: 5 additions & 5 deletions src/TibiaHousesHouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ var (
)

// TibiaHousesHouse func
func TibiaHousesHouseImpl(houseid int, BoxContentHTML string) (*HouseResponse, error) {
func TibiaHousesHouseImpl(houseid int, BoxContentHTML string) (HouseResponse, error) {
// Creating empty vars
var HouseData House

// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
return nil, fmt.Errorf("[error] TibiaHousesHouseImpl failed at goquery.NewDocumentFromReader, err: %s", err)
return HouseResponse{}, fmt.Errorf("[error] TibiaHousesHouseImpl failed at goquery.NewDocumentFromReader, err: %s", err)
}

// Running query over each div
HouseHTML, err := ReaderHTML.Find(".BoxContent table tr").First().Html()
if err != nil {
return nil, fmt.Errorf("[error] TibiaHousesHouseImpl failed at ReaderHTML.Find, err: %s", err)
return HouseResponse{}, fmt.Errorf("[error] TibiaHousesHouseImpl failed at ReaderHTML.Find, err: %s", err)
}

// Regex to get data for house
Expand All @@ -97,7 +97,7 @@ func TibiaHousesHouseImpl(houseid int, BoxContentHTML string) (*HouseResponse, e

rawHouse, err := validation.GetHouseRaw(HouseData.Houseid)
if err != nil {
return nil, err
return HouseResponse{}, err
}

HouseData.Town = rawHouse.Town
Expand Down Expand Up @@ -165,7 +165,7 @@ func TibiaHousesHouseImpl(houseid int, BoxContentHTML string) (*HouseResponse, e
}

// Build the data-blob
return &HouseResponse{
return HouseResponse{
HouseData,
Information{
APIDetails: TibiaDataAPIDetails,
Expand Down
6 changes: 3 additions & 3 deletions src/TibiaHousesOverview.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
)

// TibiaHousesOverview func
func TibiaHousesOverviewImpl(c *gin.Context, world string, town string, htmlDataCollector func(TibiaDataRequestStruct) (string, error)) (*HousesOverviewResponse, error) {
func TibiaHousesOverviewImpl(c *gin.Context, world string, town string, htmlDataCollector func(TibiaDataRequestStruct) (string, error)) (HousesOverviewResponse, error) {
var (
// Creating empty vars
HouseData, GuildhallData []HousesHouse
Expand All @@ -62,7 +62,7 @@ func TibiaHousesOverviewImpl(c *gin.Context, world string, town string, htmlData
for _, HouseType := range HouseTypes {
houses, err := makeHouseRequest(HouseType, world, town, htmlDataCollector)
if err != nil {
return nil, fmt.Errorf("[error] TibiaHousesOverviewImpl failed at makeHouseRequest, type: %s, err: %s", HouseType, err)
return HousesOverviewResponse{}, fmt.Errorf("[error] TibiaHousesOverviewImpl failed at makeHouseRequest, type: %s, err: %s", HouseType, err)
}

switch HouseType {
Expand All @@ -74,7 +74,7 @@ func TibiaHousesOverviewImpl(c *gin.Context, world string, town string, htmlData
}

// Build the data-blob
return &HousesOverviewResponse{
return HousesOverviewResponse{
HousesHouses{
World: world,
Town: town,
Expand Down
6 changes: 3 additions & 3 deletions src/TibiaKillstatistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ type KillStatisticsResponse struct {
Information Information `json:"information"`
}

func TibiaKillstatisticsImpl(world string, BoxContentHTML string) (*KillStatisticsResponse, error) {
func TibiaKillstatisticsImpl(world string, BoxContentHTML string) (KillStatisticsResponse, error) {
// Loading HTML data into ReaderHTML for goquery with NewReader
ReaderHTML, err := goquery.NewDocumentFromReader(strings.NewReader(BoxContentHTML))
if err != nil {
return nil, fmt.Errorf("[error] TibiaKillstatisticsImpl failed at goquery.NewDocumentFromReader, err: %s", err)
return KillStatisticsResponse{}, fmt.Errorf("[error] TibiaKillstatisticsImpl failed at goquery.NewDocumentFromReader, err: %s", err)
}

// Creating empty KillStatisticsData var
Expand Down Expand Up @@ -76,7 +76,7 @@ func TibiaKillstatisticsImpl(world string, BoxContentHTML string) (*KillStatisti

//
// Build the data-blob
return &KillStatisticsResponse{
return KillStatisticsResponse{
KillStatistics{
World: world,
Entries: KillStatisticsData,
Expand Down
Loading