get rid of internal

This commit is contained in:
filifa 2025-04-06 01:15:34 -04:00
parent 5763fddf4e
commit 32e72e532e
2 changed files with 16 additions and 17 deletions

View File

@ -29,7 +29,6 @@ import (
"github.com/spf13/cobra"
"scm.dairydemon.net/filifa/mlbstats/api"
"scm.dairydemon.net/filifa/mlbstats/api/models"
"scm.dairydemon.net/filifa/mlbstats/cmd/internal/statsapi"
)
var gamePk int32
@ -82,19 +81,19 @@ func patch(feed *models.BaseballGameRestObject, client *api.APIClient) error {
return err
}
func newWebsocket(gamePk int32) (*statsapi.GamedayWebsocket, <-chan error, error) {
ws, err := statsapi.NewGamedayWebsocket(gamePk)
func newWebsocket(gamePk int32) (*gamedayWebsocket, <-chan error, error) {
ws, err := newGamedayWebsocket(gamePk)
if err != nil {
return nil, nil, err
}
ch := make(chan error)
go ws.KeepAlive(10*time.Second, ch)
go ws.keepAlive(10*time.Second, ch)
return ws, ch, err
}
func handleUnexpectedClose(feed *models.BaseballGameRestObject, client *api.APIClient) (*statsapi.GamedayWebsocket, error) {
func handleUnexpectedClose(feed *models.BaseballGameRestObject, client *api.APIClient) (*gamedayWebsocket, error) {
ws, _, err := newWebsocket(feed.GamePk)
if err != nil {
return nil, err
@ -105,10 +104,10 @@ func handleUnexpectedClose(feed *models.BaseballGameRestObject, client *api.APIC
return ws, err
}
func updateFeed(feed *models.BaseballGameRestObject, ws *statsapi.GamedayWebsocket, client *api.APIClient) error {
var p statsapi.Push
func updateFeed(feed *models.BaseballGameRestObject, ws *gamedayWebsocket, client *api.APIClient) error {
var p push
err := ws.ReadJSON(&p)
if websocket.IsUnexpectedCloseError(err, statsapi.GameFinalCode, statsapi.GameUnavailableCode) {
if websocket.IsUnexpectedCloseError(err, GameFinalCode, GameUnavailableCode) {
log.Println(err)
newWs, err := handleUnexpectedClose(feed, client)

View File

@ -13,7 +13,7 @@ PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
*/
package statsapi
package cmd
import (
"net/url"
@ -25,7 +25,7 @@ import (
// Push is a struct for holding data sent to us through the websocket that we
// care about.
type Push struct {
type push struct {
UpdateId string
}
@ -36,15 +36,15 @@ const (
// GamedayWebsocket is a struct for establishing a websocket connection with
// the Stats API.
type GamedayWebsocket struct {
type gamedayWebsocket struct {
baseURL url.URL
*websocket.Conn
}
// NewGamedayWebsocket creates a statsapi.GamedayWebsocket using the Stats API
// websocket URL and establishes a connection.
func NewGamedayWebsocket(gamePk int32) (*GamedayWebsocket, error) {
ws := GamedayWebsocket{
func newGamedayWebsocket(gamePk int32) (*gamedayWebsocket, error) {
ws := gamedayWebsocket{
baseURL: url.URL{
Scheme: "wss",
Host: "ws.statsapi.mlb.com",
@ -55,7 +55,7 @@ func NewGamedayWebsocket(gamePk int32) (*GamedayWebsocket, error) {
return &ws, err
}
func (g *GamedayWebsocket) init(gamePk int32) error {
func (g *gamedayWebsocket) init(gamePk int32) error {
endpoint := url.URL{
Path: "api/v1/game/push/subscribe/gameday/" + strconv.Itoa(int(gamePk)),
}
@ -69,7 +69,7 @@ func (g *GamedayWebsocket) init(gamePk int32) error {
// SendKeepAlive sends the keep-alive message observed to be sent by MLB
// Gameday ("Gameday5").
func (g *GamedayWebsocket) SendKeepAlive() error {
func (g *gamedayWebsocket) sendKeepAlive() error {
msg := []byte("Gameday5")
err := g.Conn.WriteMessage(websocket.TextMessage, msg)
return err
@ -77,12 +77,12 @@ func (g *GamedayWebsocket) SendKeepAlive() error {
// KeepAlive sends the keep-alive message on a certain interval and sends any
// errors to ch.
func (g *GamedayWebsocket) KeepAlive(interval time.Duration, ch chan<- error) {
func (g *gamedayWebsocket) keepAlive(interval time.Duration, ch chan<- error) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for range ticker.C {
err := g.SendKeepAlive()
err := g.sendKeepAlive()
if err != nil {
ch <- err
}