games

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Game

type Game struct {
	// ID is the unique identifier for the game.
	ID string `json:"id"`
	// Name is the title of the game (e.g. "Minecraft")
	Name string `json:"name"`
	// Description contains the long-form details of the game.
	Description string `json:"description"`
	// Publisher indicates who made/released the game.
	Publisher string `json:"publisher"`
	// Year is when the game was initially released.
	Year int `json:"year"`
}

Game is the snapshot of data that represents a single game that we support in our gaming cloud.

type GameService

type GameService interface {
	// GetByID looks up a game record given its unique id.
	//
	// GET /game/:ID
	GetByID(context.Context, *GetByIDRequest) (*GetByIDResponse, error)

	// Register adds another game record to our gaming database.
	//
	// HTTP 201
	// POST /game
	Register(context.Context, *RegisterRequest) (*RegisterResponse, error)
}

GameService manages the catalog info for all of the games in our system.

PATH /v2

type GameServiceHandler

type GameServiceHandler struct {
	// Repo manages access to the underlying data store. Even when working with Frodo-powered services
	// you can still use standard Go dependency injection to get your services running.
	Repo Repo
}

GameServiceHandler implements all of the "real" functionality for the GameService.

func (*GameServiceHandler) GetByID

func (*GameServiceHandler) Register

type GetByIDRequest

type GetByIDRequest struct {
	// ID is the unique identifier of the game to look up.
	ID string `json:"id"`
}

GetByIDRequest contains all of the inputs for the GetByID operation.

type GetByIDResponse

type GetByIDResponse Game

GetByIDResponse is the record info for the game that we found.

Frodo Notes: Notice that you don't need need to define a whole new struct. You can have any of your request/response types simply alias some shared type. You don't need to repeat yourself over and over. For explicitness, it's still good to create this alias rather than having GetByID() return a Game type.

type RegisterRequest

type RegisterRequest struct {
	// Name is the title of the game (e.g. "Minecraft")
	Name string `json:"name"`
	// Description contains the long-form details of the game.
	Description string `json:"description"`
	// Publisher indicates who made/released the game.
	Publisher string `json:"publisher"`
	// Year is when the game was initially released.
	Year int `json:"year"`
}

RegisterRequest contains all of the inputs used to populate a new game record.

type RegisterResponse

type RegisterResponse Game

RegisterResponse is the complete game record as it was saved, with the ID it was assigned.

type Repo

type Repo interface {
	// GetByID fetches a game record given its unique identifier. If the game is not found,
	// you will receive nil and a 404-style error value back.
	GetByID(ctx context.Context, id string) (Game, error)
	// Create adds another game record to the store.
	Create(ctx context.Context, game Game) (Game, error)
}

Repo manages access to the data store where we keep game catalog data.

func NewRepo

func NewRepo() Repo

NewRepo constructs a new mock repo that stores high score data in-memory. Not what you'd use in production, but it serves us well for this example code.

Directories

Path Synopsis
Code generated by Frodo from games/game_service.go - DO NOT EDIT https://github.com/monadicstack/frodo Code generated by Frodo from games/game_service.go - DO NOT EDIT https://github.com/monadicstack/frodo
Code generated by Frodo from games/game_service.go - DO NOT EDIT https://github.com/monadicstack/frodo Code generated by Frodo from games/game_service.go - DO NOT EDIT https://github.com/monadicstack/frodo

Jump to

Keyboard shortcuts

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