httputils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 10 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 UnmarshalBody

func UnmarshalBody(req *http.Request, target interface{}) error

UnmarshalBody reads the body of the given HTTP request and decodes it into the provided interface.

func Write

func Write(writer http.ResponseWriter, response *ResponseDTO) error

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

func WriteAndLog

func WriteAndLog(ctx context.Context, writer http.ResponseWriter, response *ResponseDTO, log logger.Logger)

WriteAndLog writes the provided ResponseDTO as the HTTP response using the provided writer. If write call fails, it does not return the error. Instead, it logs it using the provided logger.

func WriteErrAndLog

func WriteErrAndLog(ctx context.Context, writer http.ResponseWriter, err error, log logger.Logger)

WriteErrAndLog writes the provided error as the HTTP response using the provided writer. If write call fails, it does not return the error. Instead, it logs it using the provided logger.

Types

type ResponseBodyDTO

type ResponseBodyDTO struct {
	StatusCode int         `json:"status_code"`
	CustomCode string      `json:"custom_code"`
	Data       interface{} `json:"data"`
	Errors     []string    `json:"errors"`
}

ResponseBodyDTO is the schema for all response bodies.

type ResponseDTO

type ResponseDTO struct {
	Status  int
	Headers map[string]string
	Body    interface{}
}

ResponseDTO contains all data that may be required by the router layer to send back a response to the external user.

Jump to

Keyboard shortcuts

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