create one client to use between commands

This commit is contained in:
filifa 2025-04-06 22:04:10 -04:00
parent bc91e86648
commit 3a217181b4
3 changed files with 22 additions and 14 deletions

View File

@ -19,8 +19,28 @@ import (
"errors"
"sort"
"strings"
"scm.dairydemon.net/filifa/mlbstats/api"
)
var statsAPIConfiguration = &api.Configuration{
Host: "statsapi.mlb.com",
Scheme: "https",
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
Servers: api.ServerConfigurations{
{
URL: "",
Description: "No description provided",
},
},
OperationServers: map[string]api.ServerConfigurations{
},
}
var statsAPIClient = api.NewAPIClient(statsAPIConfiguration)
func keys[V any](m map[string]V) []string {
keys := make([]string, len(m))

View File

@ -23,7 +23,6 @@ import (
"log"
"github.com/spf13/cobra"
"scm.dairydemon.net/filifa/mlbstats/api"
)
var date string
@ -33,12 +32,7 @@ var sport = sportAbbr("mlb")
func schedule(cmd *cobra.Command, args []string) {
sportId := int32(sportIDs[string(sport)])
cfg := api.NewConfiguration()
cfg.Host = "statsapi.mlb.com"
cfg.Scheme = "https"
client := api.NewAPIClient(cfg)
req := client.ScheduleAPI.Schedule(context.Background())
req := statsAPIClient.ScheduleAPI.Schedule(context.Background())
req = req.SportId(sportId)
req = req.Date(date)

View File

@ -23,7 +23,6 @@ import (
"log"
"github.com/spf13/cobra"
"scm.dairydemon.net/filifa/mlbstats/api"
)
var league leagueAbbr
@ -32,12 +31,7 @@ func standings(cmd *cobra.Command, args []string) {
var leagueIds []int32
leagueIds = append(leagueIds, leagueIDs[string(league)])
cfg := api.NewConfiguration()
cfg.Host = "statsapi.mlb.com"
cfg.Scheme = "https"
client := api.NewAPIClient(cfg)
req := client.StandingsAPI.Standings1(context.Background(), "regularSeason")
req := statsAPIClient.StandingsAPI.Standings1(context.Background(), "regularSeason")
req = req.LeagueId(leagueIds)