ctr

package
v0.0.0-...-25a1aa9 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 5 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultDecoder = func(r io.Reader, v any) error {
	return json.NewDecoder(r).Decode(v)
}
View Source
var InitLogger = SetLog

InitLogger initialization the log processing method Deprecated: SetLog instead.

Functions

func BadRequest

func BadRequest(w http.ResponseWriter, v ...any)

BadRequest writes the json-encoded error message to the response with a 400 bad request status code.

func Bytes

func Bytes(w http.ResponseWriter, bytes []byte)

Bytes writes the Bytes message to the response.

func CustomDecode

func CustomDecode(r io.Reader, v any, decoder func(r io.Reader, v any) error) error

func Decode

func Decode(r io.Reader, v any) error

func ErrorCode

func ErrorCode(w http.ResponseWriter, status int, v ...any)

ErrorCode writes the json-encoded error message to the response.

func Forbidden

func Forbidden(w http.ResponseWriter, v ...any)

Forbidden writes the json-encoded error message to the response with a 403 forbidden status code.

func Found

func Found(w http.ResponseWriter, r *http.Request, url string)

Found replies to the request with a redirect to url.

func HookError

func HookError(hook func(error) any)

func InternalError

func InternalError(w http.ResponseWriter, v ...any)

InternalError writes the json-encoded error message to the response with a 500 internal server error.

func JSON

func JSON(w http.ResponseWriter, v any, status int)

JSON writes the json-encoded error message to the response with a 400 bad request status code.

func NoContent

func NoContent(w http.ResponseWriter)

NoContent writes no content to the response.

func NotFound

func NotFound(w http.ResponseWriter, v ...any)

NotFound writes the json-encoded error message to the response with a 404 not found status code.

func NotImplemented

func NotImplemented(w http.ResponseWriter, v ...any)

NotImplemented writes the json-encoded error message to the response with a 501 not found status code.

func OK

func OK(w http.ResponseWriter, v any)

OK writes the json-encoded data to the response.

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, url string, code int)

Redirect replies to the request with a redirect to url.

func SetLog

func SetLog(l Log)

func Str

func Str(w http.ResponseWriter, str string)

Str writes the string message to the response.

func Success

func Success(w http.ResponseWriter)

Success writes ok message to the response.

func Unauthorized

func Unauthorized(w http.ResponseWriter, v ...any)

Unauthorized writes the json-encoded error message to the response with a 401 unauthorized status code.

Types

type KVLog

type KVLog interface {
	Error(msg string, vs ...any)
}

type Log

type Log interface {
	Error(vs ...any)
}

func CoverKVLog

func CoverKVLog(logger KVLog) Log

func Logger

func Logger() Log

Logger returns the default logger instance

type Validator

type Validator interface {
	Validate() error
}

Jump to

Keyboard shortcuts

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