httplib

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CookieName = "session"

CookieName is the name of the cookie used to store the session ID.

Functions

func ErrorResponseJSON

func ErrorResponseJSON(w http.ResponseWriter, httpCode int, internalCode int, err error)

ErrorResponseJSON sends error http response

func ResponseJSON

func ResponseJSON(w http.ResponseWriter, v any)

ResponseJSON sends OK JSON response

func SetCookieName

func SetCookieName(name string)

SetCookieName sets the name of the cookie used to store the session ID.

func SuccessfulResultMap

func SuccessfulResultMap() map[string]any

SuccessfulResultMap returns a map with success flag set to true and default message.

Types

type ApiError

type ApiError struct {
	HttpStatus int `json:"http_status,omitempty"`
	ErrorCode  int `json:"code"`
	Message    any `json:"message"`
	Timestamp  any `json:"timestamp"`
}

ApiError represents a structure for encoding API error responses in JSON format.

func NewApiErrFromInternalErr

func NewApiErrFromInternalErr(e InternalError, code ...int) *ApiError

NewApiErrFromInternalErr creates and returns a new instance of ApiError based on an internal error. It sets the HTTP status code to the specified value or defaults to http.StatusBadRequest if not provided.

func NewApiError

func NewApiError(code int, msg string) *ApiError

NewApiError creates and returns a new instance of ApiError with the specified error code and message. It automatically sets the timestamp to the current time in RFC1123 format.

func (ApiError) Error

func (e ApiError) Error() string

Error returns the string representation of the ApiError.

func (ApiError) String

func (e ApiError) String() string

String returns a formatted string representation of the ApiError, including HTTP status code, internal error code, and the error message.

type CreatedObjectId

type CreatedObjectId struct {
	Id   any `json:"id,omitempty" yaml:"id,omitempty"`
	UUID any `json:"uuid,omitempty" yaml:"uuid,omitempty"`
}

CreatedObjectId represents a structure for encoding the ID and UUID of a created entity.

type InternalError

type InternalError interface {
	GetCode() int
	GetMessage() string
}

type ListResult

type ListResult struct {
	Results any   `json:"results,omitempty" yaml:"results,omitempty"`
	Count   int32 `json:"count" yaml:"count"`
}

ListResult represents a structure for encoding API list of results in JSON format.

type Response

type Response struct {
	Success   bool   `json:"success" yaml:"success"`
	Timestamp string `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
	Message   string `json:"message,omitempty" yaml:"message,omitempty"`
	Data      any    `json:"data,omitempty" yaml:"data,omitempty"`
	CreatedObjectId
	RequestStatus *ApiError `json:"request_status" yaml:"request_status,omitempty"`
}

Response represents a structure for encoding API responses in JSON format.

func SuccessfulResult

func SuccessfulResult() Response

SuccessfulResult returns a Response instance with success flag set to true and default message.

Jump to

Keyboard shortcuts

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