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
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ^1.19
go-version: '1.23.x'

- name: Get golangci-lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.2
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.63.3

- name: Run golangci-lint
run: golangci-lint run
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/UnownHash/gohbem

go 1.19
go 1.23

toolchain go1.23.2
12 changes: 11 additions & 1 deletion ohbem.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gohbem

import (
"encoding/json"
"fmt"
"math"
"os"
"reflect"
Expand All @@ -14,7 +15,7 @@ import (
const MaxLevel = 100

// VERSION of gohbem, follows Semantic Versioning. (http://semver.org/)
const VERSION = "0.10.0"
const VERSION = "0.11.0"

// FetchPokemonData Fetch remote MasterFile and keep it in memory.
func (o *Ohbem) FetchPokemonData() error {
Expand All @@ -38,6 +39,7 @@ func (o *Ohbem) LoadPokemonData(filePath string) error {
return ErrMasterFileUnmarshall
}
o.PokemonData.Initialized = true
o.ClearCache()
return nil
}

Expand Down Expand Up @@ -93,6 +95,14 @@ func (o *Ohbem) WatchPokemonData() error {
o.PokemonData = pokemonData // overwrite PokemonData using new MasterFile
o.PokemonData.Initialized = true
o.ClearCache() // clean compactRankCache cache
// when provided store latest version of MasterFile under provided path
if o.MasterFileCachePath != "" {
err = o.SavePokemonData(o.MasterFileCachePath)
if err != nil {
o.log(fmt.Sprintf("Storing MasterFile cache under %s has failed!", o.MasterFileCachePath))
continue
}
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions ohbem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,20 @@ func TestIsMegaUnreleased(t *testing.T) {
output bool
}{
{0, 0, false},
{127, 1, true},
{127, 1, false},
{127, 0, false},
{150, 0, false},
{150, 1, false},
{150, 2, true},
{666, 2, false},
}

for ix, test := range tests {
testName := fmt.Sprintf("%d", ix)
t.Run(testName, func(t *testing.T) {
output, _ := ohbem.IsMegaUnreleased(test.pokemonId, test.form)
if output != test.output {
t.Errorf("got %t, want %t", output, test.output)
t.Errorf("%d:%d: got %t, want %t", test.pokemonId, test.form, output, test.output)
}
})
}
Expand Down
1 change: 1 addition & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Ohbem struct {
LevelCaps []int
Leagues map[string]League
DisableCache bool
MasterFileCachePath string // when provided: store there latest changed version of masterfile
RankingComparator RankingComparator
IncludeHundosUnderCap bool
WatcherInterval time.Duration
Expand Down
Loading
Loading