From 3a217181b4d4cdb132a3b4c9350e97c23d6bbbc1 Mon Sep 17 00:00:00 2001 From: filifa Date: Sun, 6 Apr 2025 22:04:10 -0400 Subject: [PATCH] create one client to use between commands --- cmd/common.go | 20 ++++++++++++++++++++ cmd/schedule.go | 8 +------- cmd/standings.go | 8 +------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/cmd/common.go b/cmd/common.go index d7f18b2..7f956e9 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -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)) diff --git a/cmd/schedule.go b/cmd/schedule.go index b14a907..5e45071 100644 --- a/cmd/schedule.go +++ b/cmd/schedule.go @@ -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) diff --git a/cmd/standings.go b/cmd/standings.go index ca4b4ea..8c61f86 100644 --- a/cmd/standings.go +++ b/cmd/standings.go @@ -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)