store

package
v0.0.0-...-3517908 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package store persists game data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenPg

func OpenPg(rawURL string) (*sql.DB, error)

OpenPg opens a connection to the Postgres database with the given URL.

Types

type MutMap

type MutMap struct {
	// contains filtered or unexported fields
}

MutMap is an in memory team score store.

func NewMutMap

func NewMutMap(onNewTeam, onNewLeader chan string) *MutMap

NewMutMap creates a new empty MutMap.

func (*MutMap) Close

func (mm *MutMap) Close()

Close closes the store (but MutMap has no connection)

func (*MutMap) CreateTeam

func (mm *MutMap) CreateTeam(teamID string) (server.Team, error)

CreateTeam creates a new team, an error means the ID is taken.

func (*MutMap) FindByID

func (mm *MutMap) FindByID(teamID string) (server.Team, error)

FindByID returns a single team if found by ID.

func (*MutMap) GetLeaderboard

func (mm *MutMap) GetLeaderboard() (server.Leaderboard, error)

GetLeaderboard returns the highest scoring teams.

func (*MutMap) RecordClicks

func (mm *MutMap) RecordClicks(teamID string, count int64) (server.Team, error)

RecordClicks stores clicks for the given team.

type Postgres

type Postgres struct {
	// contains filtered or unexported fields
}

Postgres is a postrges backed team score store.

func NewPostgres

func NewPostgres(db *sql.DB, name string, onNewTeam, onNewLeader chan string) (*Postgres, error)

NewPostgres creates a Postgres backed by the given table and DB. The table is created if it does not exist.

func (*Postgres) Close

func (s *Postgres) Close()

Close closes the store (its database connection)

func (*Postgres) CreateTeam

func (s *Postgres) CreateTeam(teamID string) (server.Team, error)

CreateTeam creates a new team, an error means the ID is taken.

func (*Postgres) FindByID

func (s *Postgres) FindByID(teamID string) (server.Team, error)

FindByID returns a single team if found by ID.

func (*Postgres) GetLeaderboard

func (s *Postgres) GetLeaderboard() (server.Leaderboard, error)

GetLeaderboard returns the highest scoring teams.

func (*Postgres) RecordClicks

func (s *Postgres) RecordClicks(teamID string, count int64) (server.Team, error)

RecordClicks stores clicks for the given team.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL