Documentation ¶
Overview ¶
Package isugata is HTTP response validator for ISUCON benchmarker
Index ¶
- Constants
- Variables
- func Validate(res *http.Response, opts ...ValidateOpt) error
- type JSONArrayValidateOpt
- func JSONArrayLengthEquals[V any](length int) JSONArrayValidateOpt[V]
- func JSONArrayLengthRange[V any](min, max int) JSONArrayValidateOpt[V]
- func JSONArrayValidateEach[V any](opts ...JSONValidateOpt[V]) JSONArrayValidateOpt[V]
- func JSONArrayValidateOrder[V any, I constraints.Ordered](idxFunc func(v V) I, ord order) JSONArrayValidateOpt[V]
- type JSONValidateOpt
- type ValidateOpt
- func WithContentType(contentType string) ValidateOpt
- func WithJSONArrayValidation[V any](opts ...JSONArrayValidateOpt[V]) ValidateOpt
- func WithJSONValidation[V any](opts ...JSONValidateOpt[V]) ValidateOpt
- func WithQRCodeEqual(size int, corrLevel correctionLevel, content string, ...) ValidateOpt
- func WithStatusCode(code int) ValidateOpt
Constants ¶
const ( // Asc is ascending order Asc order = "asc" // Desc is descending order Desc order = "desc" )
const ( // CorrectionLevelL is correction level L (approx 7%) CorrectionLevelL correctionLevel = "L" // CorrectionLevelM is correction level M (approx 15%) CorrectionLevelM correctionLevel = "M" // CorrectionLevelQ is correction level Q (approx 25%) CorrectionLevelQ correctionLevel = "Q" // CorrectionLevelH is correction level H (approx 30%) CorrectionLevelH correctionLevel = "H" )
Variables ¶
var ( // ErrUndecodableBody is returned when the body cannot be decoded ErrUndecodableBody = errors.New("undecodable body") // ErrInvalidStatusCode is returned when the status code is invalid ErrInvalidStatusCode = errors.New("invalid status code") // ErrInvalidContentType is returned when the Content-Type header is invalid ErrInvalidContentType = errors.New("invalid Content-Type header") // ErrInvalidBody is returned when the body doesn't match the expected ErrInvalidBody = errors.New("invalid body") )
Functions ¶
Types ¶
type JSONArrayValidateOpt ¶
JSONArrayValidateOpt is function type to validate JSON array body
func JSONArrayLengthEquals ¶
func JSONArrayLengthEquals[V any](length int) JSONArrayValidateOpt[V]
JSONArrayLengthEquals validates if JSON array body length equals to length
func JSONArrayLengthRange ¶
func JSONArrayLengthRange[V any](min, max int) JSONArrayValidateOpt[V]
JSONArrayLengthRange validates if JSON array body length is in range [min, max]
func JSONArrayValidateEach ¶
func JSONArrayValidateEach[V any](opts ...JSONValidateOpt[V]) JSONArrayValidateOpt[V]
JSONArrayValidateEach validates each element of JSON array body with opts
func JSONArrayValidateOrder ¶
func JSONArrayValidateOrder[V any, I constraints.Ordered](idxFunc func(v V) I, ord order) JSONArrayValidateOpt[V]
JSONArrayValidateOrder validates if JSON array body is ordered by idxFunc in ord
type JSONValidateOpt ¶
JSONValidateOpt is function type to validate JSON body
func JSONArrayFieldValidate ¶
func JSONArrayFieldValidate[V, F any](name string, opts ...JSONArrayValidateOpt[F]) JSONValidateOpt[V]
JSONArrayFieldValidate validates JSON array filed with opts
func JSONEquals ¶
func JSONEquals[V comparable](v V) JSONValidateOpt[V]
JSONEquals validates if JSON body deeply equals to v
func JSONFieldValidate ¶
func JSONFieldValidate[V, F any](name string, opts ...JSONValidateOpt[F]) JSONValidateOpt[V]
JSONFieldValidate validates JSON filed with opts
type ValidateOpt ¶
ValidateOpt is function type to validate http.Response
func WithContentType ¶
func WithContentType(contentType string) ValidateOpt
WithContentType validates if the Content-Type header starts with contentType
func WithJSONArrayValidation ¶
func WithJSONArrayValidation[V any](opts ...JSONArrayValidateOpt[V]) ValidateOpt
WithJSONArrayValidation decodes JSON array body and validates it with opts
func WithJSONValidation ¶
func WithJSONValidation[V any](opts ...JSONValidateOpt[V]) ValidateOpt
WithJSONValidation decodes JSON body and validates it with opts
func WithQRCodeEqual ¶
func WithQRCodeEqual(size int, corrLevel correctionLevel, content string, decryptFunc func(string) (string, error)) ValidateOpt
WithQRCodeEqual validates if the QR code equals to the expected
func WithStatusCode ¶
func WithStatusCode(code int) ValidateOpt
WithStatusCode validates if the status code equals to code