xhttp

package
v0.0.0-...-4d0c6f8 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderOrigin      = "Origin"
	HeaderContentType = "Content-Type"

	ContentTypeJSON = "application/json"
)

Variables

This section is empty.

Functions

func DoJSON

func DoJSON(c Client, resbody any, req *http.Request) error

If c is nill, use http.DefaultClient.

func GetJSON

func GetJSON(ctx context.Context, c Client, resbody any, url string) error

func JSONHandler

func JSONHandler[T any](h func(http.ResponseWriter, *http.Request, T)) http.Handler

func LogHandler

func LogHandler(h http.Handler) http.Handler

func NewRequestJSON

func NewRequestJSON(ctx context.Context, method, url string, reqbody any) (*http.Request, error)

func PostJSON

func PostJSON(ctx context.Context, c Client, resbody any, url string, reqbody any) error

func WriteJSON

func WriteJSON(w http.ResponseWriter, statusCode int, data any)

Types

type Client

type Client interface {
	Do(*http.Request) (*http.Response, error)
}

type ErrorJSON

type ErrorJSON struct {
	Message string `json:"message"`
}

type NGStatusError

type NGStatusError struct {
	// Response.Body is consumed and set Body.
	Response *http.Response
	Body     []byte
}

NGStatusError is returned if a status code of Response is over 400.

func (*NGStatusError) Error

func (e *NGStatusError) Error() string

Jump to

Keyboard shortcuts

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