vote

package
v0.0.0-...-66ffae8 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package vote provides functionality around reading and writing votes.

Index

Constants

View Source
const (
	// DBName is the name of the database for the votes API.
	DBName = "votes"
)

Variables

This section is empty.

Functions

func CreateTableIfNotExist

func CreateTableIfNotExist(db *sql.DB) error

CreateTableIfNotExist creates the "votes" table if it does not exist already.

Types

type DB

type DB interface {
	Store(in VoteInput) error
	BatchStore(in []VoteInput) error
	Result(voterID string) (vote string, err error)
	Results() (results []ResultCount, err error)
}

DB is the interface for all the operations allowed on votes.

func NewSQLDB

func NewSQLDB(db *sql.DB) DB

NewSQLDB creates a sql database to read and store votes.

type ErrNoVote

type ErrNoVote struct {
	VoterID string
}

ErrNoVote means a voter ID has not voted.

func (ErrNoVote) Error

func (e ErrNoVote) Error() string

type ResultCount

type ResultCount struct {
	Result string `json:"result"`
	Count  int    `json:"count"`
}

ResultCount is a pair of a vote result and the sum of votes for the result.

type VoteInput

type VoteInput struct {
	VoterID string `json:"voter_id"`
	Vote    string `json:"vote"`
}

VoteInput represents a single vote request.

Jump to

Keyboard shortcuts

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