Documentation
¶
Index ¶
- Variables
- func DoGenerateFormatMany(r JsonRequest[GenerateRequest, FormatParam, GenerateFormatManyQuery]) (any, int)
- func DoGenerateFormatSingle(r JsonRequest[None, FormatParam, GenerateFormatSingleQuery]) (any, int)
- func DoPuzzleFormatSingle(r JsonRequest[None, PuzzleParams, PuzzleFormatSingleQuery]) (any, int)
- func DoSolutionsFormatComplex(r JsonRequest[SolveKind, FormatParam, SolutionsFormatComplexQuery]) (any, int)
- func DoSolveFormatComplex(r JsonRequest[SolveKind, FormatParam, SolveFormatSingleQuery]) (any, int)
- func DoSolveFormatSingle(r JsonRequest[None, PuzzleParams, SolveFormatSingleQuery]) (any, int)
- func GetRouter() chi.Router
- func JsonHandle(handle func(w http.ResponseWriter, r *http.Request) (any, int)) http.HandlerFunc
- func JsonRoute[B any, P any, Q any](handler JsonHandler[B, P, Q]) http.HandlerFunc
- func ParamsToMap(r *http.Request) any
- func ParseBody[T any](r *http.Request) (T, error)
- func ParseMap[T any](m any) (T, error)
- func QueryToMap(r *http.Request) any
- func Start(addr string) error
- type CanValidate
- type ConstraintDifference
- type ConstraintDivisible
- type ConstraintMagic
- type ConstraintOrder
- type ConstraintScalePair
- type ConstraintSumCell
- type ConstraintSumCells
- type ConstraintSumValue
- type ConstraintUnique
- type Constraints
- type DirectionInt
- type Format
- type FormatParam
- type GenerateCount
- type GenerateFormatManyJson
- type GenerateFormatManyQuery
- type GenerateFormatSingleJson
- type GenerateFormatSingleQuery
- type GenerateKind
- type GenerateRequest
- type GenerateSeed
- type GeneratedPuzzle
- type IDParam
- type Index
- type JsonError
- type JsonHandler
- type JsonRequest
- type None
- type Optional
- type OptionsPDF
- type Position
- type PuzzleData
- type PuzzleDimension
- type PuzzleFormatSingleJson
- type PuzzleFormatSingleQuery
- type PuzzleParams
- type PuzzleSolveStep
- type ReflectConsumer
- type ReflectIterator
- type ReflectShouldConsume
- type Reflector
- type RelativeIndex
- type RelativePosition
- type SolutionsFormatComplexJson
- type SolutionsFormatComplexQuery
- type SolutionsFormatComplexSolution
- type SolveFormatComplexJson
- type SolveFormatComplexQuery
- type SolveFormatSingleJson
- type SolveFormatSingleQuery
- type SolveKind
- type Trim
- type ValidateContext
- type Validation
- type Validator
- func (v *Validator) Add(format string, args ...any)
- func (v *Validator) AddField(field string, format string, args ...any)
- func (v Validator) Consume(rv reflect.Value)
- func (v Validator) Field(field string) Validator
- func (v Validator) ForField(field reflect.StructField) ReflectConsumer
- func (v Validator) ForIndex(index int) ReflectConsumer
- func (v Validator) ForKey(key string) ReflectConsumer
- func (v Validator) IsValid() bool
- func (v Validator) Validate(value any)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( JsonParamsParseCode = "ERR_PARSE_PARAMS" JsonQueryParseCode = "ERR_PARSE_QUERY" JsonBodyParseCode = "ERR_PARSE_BODY" JsonValidateCode = "ERR_VALIDATE_REQUEST" JsonValidateMessage = "Invalid request" )
View Source
var ( CanValidateType = reflect.TypeOf((*CanValidate)(nil)).Elem() ValidateReflector = NewReflector(func(t reflect.Type) bool { return t.Implements(CanValidateType) }) )
View Source
var DifficultyMap = map[string]su.ClearLimit{ "": su.DifficultyMedium, "beginner": su.DifficultyBeginner, "easy": su.DifficultyEasy, "medium": su.DifficultyMedium, "hard": su.DifficultyHard, "tricky": su.DifficultyTricky, "diabolical": su.DifficultyDiabolical, "fiendish": su.DifficultyFiendish, "custom": customClearLimit, }
Functions ¶
func DoGenerateFormatMany ¶
func DoGenerateFormatMany(r JsonRequest[GenerateRequest, FormatParam, GenerateFormatManyQuery]) (any, int)
func DoGenerateFormatSingle ¶
func DoGenerateFormatSingle(r JsonRequest[None, FormatParam, GenerateFormatSingleQuery]) (any, int)
func DoPuzzleFormatSingle ¶
func DoPuzzleFormatSingle(r JsonRequest[None, PuzzleParams, PuzzleFormatSingleQuery]) (any, int)
func DoSolutionsFormatComplex ¶
func DoSolutionsFormatComplex(r JsonRequest[SolveKind, FormatParam, SolutionsFormatComplexQuery]) (any, int)
func DoSolveFormatComplex ¶
func DoSolveFormatComplex(r JsonRequest[SolveKind, FormatParam, SolveFormatSingleQuery]) (any, int)
func DoSolveFormatSingle ¶
func DoSolveFormatSingle(r JsonRequest[None, PuzzleParams, SolveFormatSingleQuery]) (any, int)
func JsonHandle ¶
func JsonHandle(handle func(w http.ResponseWriter, r *http.Request) (any, int)) http.HandlerFunc
func JsonRoute ¶
func JsonRoute[B any, P any, Q any](handler JsonHandler[B, P, Q]) http.HandlerFunc
func ParamsToMap ¶
func QueryToMap ¶
Types ¶
type CanValidate ¶
type CanValidate interface {
Validate(v Validator)
}
type ConstraintDifference ¶
type ConstraintDifference struct {
Min int `json:"min"`
Max int `json:"max"`
Cells *[]Position `json:"cells"`
Relative *[]RelativePosition `json:"relative"`
Exclude *[]Position `json:"exclude"`
}
type ConstraintDivisible ¶
type ConstraintMagic ¶
type ConstraintMagic struct {
Center Position `json:"center"`
}
type ConstraintOrder ¶
type ConstraintOrder struct {
Cells *[]Position `json:"cells"`
Relative *[]RelativePosition `json:"relative"`
Direction DirectionInt `json:"direction"`
}
type ConstraintScalePair ¶
type ConstraintSumCell ¶
type ConstraintSumCell struct {
Sum RelativePosition `json:"sum"`
SumRelative Trim[bool] `json:"sumRelative"`
Cells *[]Position `json:"cells"`
Relative *[]RelativePosition `json:"relative"`
}
type ConstraintSumCells ¶
type ConstraintSumCells struct {
Sum []RelativePosition `json:"sum"`
SumRelative Trim[bool] `json:"sumRelative"`
Cells *[]Position `json:"cells"`
Relative *[]RelativePosition `json:"relative"`
}
type ConstraintSumValue ¶
type ConstraintSumValue struct {
Sum int `json:"sum"`
Cells *[]Position `json:"cells"`
Relative *[]RelativePosition `json:"relative"`
}
func (ConstraintSumValue) Validate ¶
func (c ConstraintSumValue) Validate(v Validator)
type ConstraintUnique ¶
type ConstraintUnique struct {
Cells *[]Position `json:"cells"`
Relative *[]RelativePosition `json:"relative"`
Same Trim[bool] `json:"same"`
}
type Constraints ¶
type Constraints struct {
SumValues []ConstraintSumValue `json:"sumValues"`
SumCell []ConstraintSumCell `json:"sumCell"`
SumCells []ConstraintSumCells `json:"sumCells"`
Uniques []ConstraintUnique `json:"uniques"`
Orders []ConstraintOrder `json:"orders"`
Magics []ConstraintMagic `json:"magics"`
ScalePairs []ConstraintScalePair `json:"scalePairs"`
Differences []ConstraintDifference `json:"differences"`
Divisibles []ConstraintDivisible `json:"divisibles"`
}
type DirectionInt ¶
type DirectionInt int
func (*DirectionInt) Validate ¶
func (d *DirectionInt) Validate(v Validator)
type FormatParam ¶
type FormatParam struct {
Format Format `json:"format"`
}
func (*FormatParam) Validate ¶
func (f *FormatParam) Validate(v Validator)
type GenerateCount ¶
type GenerateCount int
func (*GenerateCount) Validate ¶
func (g *GenerateCount) Validate(v Validator)
type GenerateFormatManyJson ¶
type GenerateFormatManyJson struct {
Seed int64 `json:"seed"`
Kind GenerateKind `json:"kind"`
Puzzles []GeneratedPuzzle `json:"puzzles"`
}
type GenerateFormatManyQuery ¶
type GenerateFormatManyQuery struct {
PDF OptionsPDF `json:"pdf"`
}
type GenerateFormatSingleJson ¶
type GenerateFormatSingleJson struct {
Seed int64 `json:"seed"`
Puzzles []GeneratedPuzzle `json:"puzzles"`
}
type GenerateFormatSingleQuery ¶
type GenerateFormatSingleQuery struct {
GenerateKind
PDF OptionsPDF `json:"pdf"`
}
type GenerateKind ¶
type GenerateKind struct {
Count Trim[GenerateCount] `json:"count"`
Seed Trim[GenerateSeed] `json:"seed"`
Difficulty string `json:"difficulty"`
MinCost Trim[int] `json:"minCost"`
MaxCost Trim[int] `json:"maxCost"`
MaxPlacements Trim[int] `json:"maxPlacements"`
MaxSteps Trim[int] `json:"maxSteps"`
MaxBatches Trim[int] `json:"maxBatches"`
Symmetric Trim[bool] `json:"symmetric"`
BoxWidth Trim[PuzzleDimension] `json:"boxWidth"`
BoxHeight Trim[PuzzleDimension] `json:"boxHeight"`
Techniques map[string]Trim[int] `json:"techniques"`
Constraints Constraints `json:"constraints"`
Candidates Trim[bool] `json:"candidates"`
State Trim[bool] `json:"state"`
Solutions Trim[bool] `json:"solutions"`
SolutionSteps Trim[bool] `json:"solutionSteps"`
SolutionStates Trim[bool] `json:"solutionStates"`
TryCount Trim[int] `json:"tryCount"`
TryAttempts Trim[int] `json:"tryAttempts"`
TryClears Trim[int] `json:"tryClears"`
}
func (*GenerateKind) Validate ¶
func (r *GenerateKind) Validate(v Validator)
type GenerateRequest ¶
type GenerateRequest struct {
Seed GenerateSeed `json:"seed"`
Kinds []GenerateKind `json:"kinds"`
}
func (GenerateRequest) Validate ¶
func (r GenerateRequest) Validate(v Validator)
type GenerateSeed ¶
type GenerateSeed int64
func (*GenerateSeed) Validate ¶
func (g *GenerateSeed) Validate(v Validator)
type GeneratedPuzzle ¶
type GeneratedPuzzle struct {
Difficulty string `json:"difficulty,omitempty"`
Puzzle PuzzleData `json:"puzzle"`
Duration string `json:"duration"`
Solution *PuzzleData `json:"solution,omitempty"`
Steps []PuzzleSolveStep `json:"steps,omitempty"`
Solver *su.Solver `json:"-"`
}
type JsonError ¶
type JsonError struct {
Message string `json:"message"`
Code string `json:"code"`
Validations []Validation `json:"validations,omitempty"`
}
func JsonErrorFromParse ¶
func JsonErrorFromValidations ¶
func JsonErrorFromValidations(message string, code string, validations []Validation) JsonError
type JsonHandler ¶
type JsonRequest ¶
type JsonRequest[B any, P any, Q any] struct { Body B Params P Query Q Request *http.Request Response http.ResponseWriter Validate ValidateContext }
func (JsonRequest[B, P, Q]) SendJson ¶
func (r JsonRequest[B, P, Q]) SendJson(data any, status int) (any, int)
func (JsonRequest[B, P, Q]) SendText ¶
func (r JsonRequest[B, P, Q]) SendText(text string, status int) (any, int)
func (JsonRequest[B, P, Q]) URL ¶
func (r JsonRequest[B, P, Q]) URL() url.URL
type OptionsPDF ¶
type OptionsPDF struct {
PuzzlesWide Trim[int] `json:"puzzlesWide"`
PuzzlesHigh Trim[int] `json:"puzzlesHigh"`
}
func (*OptionsPDF) Validate ¶
func (o *OptionsPDF) Validate(v Validator)
type PuzzleData ¶
type PuzzleData struct {
BoxWidth int `json:"boxWidth,omitempty"`
BoxHeight int `json:"boxHeight,omitempty"`
Values [][]int `json:"values"`
Candidates [][][]int `json:"candidates,omitempty"`
Encoded string `json:"encoded,omitempty"`
State string `json:"state,omitempty"`
Puzzle *su.Puzzle `json:"-"`
}
type PuzzleDimension ¶
type PuzzleDimension int
func (*PuzzleDimension) Validate ¶
func (d *PuzzleDimension) Validate(v Validator)
type PuzzleFormatSingleJson ¶
type PuzzleFormatSingleQuery ¶
type PuzzleParams ¶
type PuzzleParams struct {
FormatParam
IDParam
}
type PuzzleSolveStep ¶
type PuzzleSolveStep struct {
Technique string `json:"technique"`
Index int `json:"index"`
Batch int `json:"batch"`
Cost int `json:"cost"`
Placement bool `json:"placement"`
Row int `json:"row"`
Col int `json:"col"`
Before int `json:"before"`
BeforeCandidates []int `json:"beforeCandidates"`
After int `json:"after"`
AfterCandidates []int `json:"afterCandidates"`
RunningCost int `json:"runningCost"`
RunningPlacements int `json:"runningPlacements"`
State *PuzzleData `json:"state,omitempty"`
Log su.SolverLog `json:"-"`
}
type ReflectConsumer ¶
type ReflectConsumer interface {
Consume(v reflect.Value)
ForIndex(index int) ReflectConsumer
ForField(field reflect.StructField) ReflectConsumer
ForKey(key string) ReflectConsumer
}
type ReflectIterator ¶
type ReflectIterator func(value reflect.Value, consumer ReflectConsumer)
type ReflectShouldConsume ¶
type Reflector ¶
type Reflector struct {
Iterators map[reflect.Type][]ReflectIterator
ShouldConsume ReflectShouldConsume
}
func NewReflector ¶
func NewReflector(should ReflectShouldConsume) *Reflector
func (*Reflector) Consume ¶
func (r *Reflector) Consume(value any, consumer ReflectConsumer)
type RelativeIndex ¶
type RelativeIndex int
func (*RelativeIndex) Validate ¶
func (d *RelativeIndex) Validate(v Validator)
type RelativePosition ¶
type RelativePosition struct {
Col RelativeIndex `json:"col"`
Row RelativeIndex `json:"row"`
}
type SolutionsFormatComplexJson ¶
type SolutionsFormatComplexJson struct {
BoxWidth int `json:"boxWidth"`
BoxHeight int `json:"boxHeight"`
Puzzle [][]int `json:"puzzle"`
Duration string `json:"duration"`
Solutions []SolutionsFormatComplexSolution `json:"solutions"`
}
type SolutionsFormatComplexQuery ¶
type SolutionsFormatComplexQuery struct {
Steps Trim[bool] `json:"steps"`
States Trim[bool] `json:"stepStates"`
Limit Trim[int] `json:"limit"`
}
func (*SolutionsFormatComplexQuery) Validate ¶
func (q *SolutionsFormatComplexQuery) Validate(v Validator)
type SolutionsFormatComplexSolution ¶
type SolutionsFormatComplexSolution struct {
Solution [][]int `json:"solution"`
Cost int `json:"cost"`
Steps []PuzzleSolveStep `json:"steps,omitempty"`
}
type SolveFormatComplexJson ¶
type SolveFormatComplexJson struct {
BoxWidth int `json:"boxWidth"`
BoxHeight int `json:"boxHeight"`
Puzzle [][]int `json:"puzzle"`
Solution [][]int `json:"solution"`
Unique bool `json:"unique"`
Duration string `json:"duration"`
Cost int `json:"cost"`
Steps []PuzzleSolveStep `json:"steps,omitempty"`
}
type SolveFormatComplexQuery ¶
type SolveFormatSingleJson ¶
type SolveFormatSingleJson struct {
BoxWidth int `json:"boxWidth"`
BoxHeight int `json:"boxHeight"`
Puzzle [][]int `json:"puzzle"`
Solution [][]int `json:"solution"`
Unique bool `json:"unique"`
Duration string `json:"duration"`
Cost int `json:"cost"`
Steps []PuzzleSolveStep `json:"steps,omitempty"`
}
type SolveFormatSingleQuery ¶
type SolveKind ¶
type SolveKind struct {
BoxWidth PuzzleDimension `json:"boxWidth"`
BoxHeight PuzzleDimension `json:"boxHeight"`
Puzzle [][]int `json:"puzzle"`
MinCost int `json:"minCost"`
MaxCost int `json:"maxCost"`
MaxPlacements int `json:"maxPlacements"`
MaxSteps int `json:"maxSteps"`
MaxBatches int `json:"maxBatches"`
Techniques map[string]int `json:"techniques"`
Constraints Constraints `json:"constraints"`
Candidates bool `json:"candidates"`
SolutionSteps bool `json:"solutionSteps"`
SolutionStates bool `json:"solutionStates"`
}
type ValidateContext ¶
type Validation ¶
type Validator ¶
type Validator struct {
Path []string
Validations *[]Validation
Context ValidateContext
}
func NewValidator ¶
func NewValidator() Validator
func (Validator) ForField ¶
func (v Validator) ForField(field reflect.StructField) ReflectConsumer
func (Validator) ForIndex ¶
func (v Validator) ForIndex(index int) ReflectConsumer
func (Validator) ForKey ¶
func (v Validator) ForKey(key string) ReflectConsumer
Click to show internal directories.
Click to hide internal directories.