httputils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetClientIP

func GetClientIP(req *http.Request) (string, error)

GetClientIP extracts the client IP Address from the given HTTP request.

func GetOwnIP

func GetOwnIP() (string, error)

GetOwnIP gets the IP address of the host machine.

func Is2xx added in v1.1.0

func Is2xx(status int) bool

Is2xx returns true if the provided status belongs to the 2xx family.

func SetReqCtx added in v1.1.0

func SetReqCtx(targetCtx context.Context, data *RequestContextData) context.Context

SetReqCtx puts the request's context data into the target context and returns the new context.

func Write

func Write(writer http.ResponseWriter, status int, headers map[string]string, body interface{})

Write writes the provided data as the HTTP response using the provided writer.

Types

type RequestContextData added in v1.1.0

type RequestContextData struct {
	// ID is the unique identifier of this request.
	ID string
}

RequestContextData is an HTTP request's context information.

func GetReqCtx added in v1.1.0

func GetReqCtx(targetCtx context.Context) *RequestContextData

GetReqCtx extracts the request's context data from the target context and returns it.

Jump to

Keyboard shortcuts

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