Categorygithub.com/goccha/problems
repositorypackage
0.2.0-beta.9
Repository: https://github.com/goccha/problems.git
Documentation: pkg.go.dev

# README

Problems

Problem Details for HTTP APIs RFC7807

RFC9457 HTTP JSON Problem Details

Simple Usage

problem := problems.New(problems.Instance("/users")).NotFound("user not found")

Bad Request (RFC7807)

if err := validate.Struct(s); err != nil {
    problems.New(problems.Path(req), problems.InvalidParams(err)).BadRequest("Invalid Parameters").JSON(ctx, req.Writer)
	return
}

Bad Request (RFC9457)

if err := validate.Struct(s); err != nil {
    problems.New(problems.Path(req), problems.ValidationErrors(err)).BadRequest("Invalid Parameters").JSON(ctx, req.Writer)
	return
}

Conversion to error

err := problems.New().Unauthorized("password mismatch").Wrap()
problems.Of(context.TODO, "/login", err).JSON(ctx, req.Writer)