api

package
v2.0.0-...-caa76b4 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: CC0-1.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllPhrasesRoute

func GetAllPhrasesRoute(w http.ResponseWriter, r *http.Request)

GetAllPhrasesRoute gets all the phrases for the system

func GetRandomPhraseRoute

func GetRandomPhraseRoute(w http.ResponseWriter, r *http.Request)

GetRandomPhraseRoute gets a random phrase

func SetupRouter

func SetupRouter() *chi.Mux

SetupRouter sets up and returns a new chi router

func TestEndpoint

func TestEndpoint(method string, endpoint string, data io.Reader, handler http.HandlerFunc, valid bool) (code int, body *bytes.Buffer, err error)

TestEndpoint allows an easy way to test HTTP end points in unit testing

Types

type Config

type Config struct {
	AuthenticationToken string
	Port                string
	PhraseBookLocation  string
}

The Config struct holds general configuration options for the application

func LoadConfig

func LoadConfig() *Config

LoadConfig will load up a new configuration struct with sane defaults if none provided

type Pair

type Pair struct {
	Esperanto string `json:"esperanto"`
	English   string `json:"english"`
}

The Pair struct provides a simple Key/Value structure of an Esperanto phrase and an English translation

func LoadPhrasebook

func LoadPhrasebook() []Pair

LoadPhrasebook will load up the phrasebook.txt file, which is a | separated file with an Esperanto phrase and English translation on each line

func (*Pair) Bind

func (data *Pair) Bind(r *http.Request) error

Bind allows binding the struct for use in chi render

Jump to

Keyboard shortcuts

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