api

package
v0.0.0-...-14c0c35 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest   = GameError{StatusCode: http.StatusBadRequest, Type: "api_error", Message: "Cannot process current request"}
	ErrUserNotFound = GameError{StatusCode: http.StatusBadRequest, Type: "user_not_found", Message: "Cannot find the given username"}
	ErrInvalidJSON  = GameError{StatusCode: http.StatusBadRequest, Type: "invalid_json", Message: "Invalid or malformed JSON"}
	// decide between conflict and bad request
	ErrAlreadyExists = GameError{StatusCode: http.StatusConflict, Type: "duplicate_entry", Message: "Another entity has the same value as this field"}
	ErrWrongClick    = GameError{StatusCode: http.StatusBadRequest, Type: "click_not_allowed", Message: "May be a cell clicked twice or an invalid click type"}
)

Functions

func Start

func Start(port string)

Types

type GameError

type GameError struct {
	StatusCode int    `json:"-"`
	Type       string `json:"type"`
	Message    string `json:"message,omitempty"`
}

func (GameError) Send

func (e GameError) Send(w http.ResponseWriter) error

type LostResponse

type LostResponse struct {
	Message      string        `json:"message"`
	Clicks       int           `json:"clicks"`
	GameDuration time.Duration `json:"game_duration"`
}

type ResponseAPI

type ResponseAPI struct {
	Success bool        `json:"success"`
	Status  int         `json:"status,omitempty"`
	Result  interface{} `json:"result,omitempty"`
}

func LostGame

func LostGame(clicks int, username string) *ResponseAPI

func Success

func Success(result interface{}, status int) *ResponseAPI

func (*ResponseAPI) Send

func (r *ResponseAPI) Send(w http.ResponseWriter)

type Services

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

Jump to

Keyboard shortcuts

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