response

package
v1.1.24 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 2 Imported by: 2

README

Response builder

Default response builder with body and error.

Usage

func CreateUser(w http.ResponseWriter, r *http.Request) {
  type User struct {
    Name string
    Age int
  }

  user := User{
    Name: "John",
    Age: 21,
  }

  SuccessResponse(w, user, http.StatusCreated)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default[Body any, Err any](w http.ResponseWriter, body Body, responseErr Err, status int)

func ErrorResponse

func ErrorResponse[Err any](w http.ResponseWriter, responseErr Err, status int)

func SuccessResponse

func SuccessResponse[Body any](w http.ResponseWriter, body Body, status int)

Types

type DefaultResponse

type DefaultResponse[T any, E any] struct {
	Error E `json:"error"`
	Body  T `json:"body"`
}

Jump to

Keyboard shortcuts

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