Skip to content

Commit

Permalink
updating function names
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalghost-dev committed Jun 2, 2024
1 parent a6fc061 commit 16609d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions connections/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ func baseApiCall(url string, target interface{}) {
if err != nil {
log.Fatalf("Error making GET request: %v", err)
}
defer res.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {

Check failure on line 24 in connections/connection.go

View workflow job for this annotation

GitHub Actions / linter

SA9003: empty branch (staticcheck)

}
}(res.Body)

if res.StatusCode == http.StatusNotFound {
fmt.Println(errorColor.Render("Couldn't find that Pokémon... perhaps its named was misspelled?"))
Expand All @@ -36,7 +41,7 @@ func baseApiCall(url string, target interface{}) {
}
}

func NameApiCall(pokemonName string, baseURL string) string {
func PokemonNameApiCall(pokemonName string, baseURL string) string {
type Pokemon struct {
Name string `json:"name"`
}
Expand All @@ -49,7 +54,7 @@ func NameApiCall(pokemonName string, baseURL string) string {
return pokemon.Name
}

func TypeApiCall(pokemonName string, baseURL string) {
func PokemonTypeApiCall(pokemonName string, baseURL string) {
type Pokemon struct {
Types []struct {
Slot int `json:"slot"`
Expand Down
2 changes: 1 addition & 1 deletion flags/pokemonflagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func SetupPokemonFlagSet() (*flag.FlagSet, *bool) {
func TypesFlag() error {
pokemonName := os.Args[1]

connections.TypeApiCall(pokemonName, "https://pokeapi.co/api/v2/pokemon/")
connections.PokemonTypeApiCall(pokemonName, "https://pokeapi.co/api/v2/pokemon/")

return nil
}
2 changes: 1 addition & 1 deletion subcommands/pokemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func PokemonCommand() {
os.Exit(1)
}

pokemonName := connections.NameApiCall(PokemonName, "https://pokeapi.co/api/v2/pokemon/")
pokemonName := connections.PokemonNameApiCall(PokemonName, "https://pokeapi.co/api/v2/pokemon/")
capitalizedString := cases.Title(language.English).String(pokemonName)

fmt.Printf("Selected Pokémon: %s\n", capitalizedString)
Expand Down

0 comments on commit 16609d3

Please sign in to comment.