common

package
v1.0.1-beta.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const AppErrorHeader = "X-App-Error-Code"

AppErrorHeader - a http response header to send an application error code

Variables

This section is empty.

Functions

func CheckCrossOrigin

func CheckCrossOrigin(w http.ResponseWriter, r *http.Request) bool

func ConfigRateLimits

func ConfigRateLimits()

ConfigRateLimits - configure the rate limits

func Done

func Done()

Done - call this when the program needs to stop and notify all workers

func GetRootContext

func GetRootContext() context.Context

GetRootContext - get the root context for the server * This will be used to control shutting down the server but cleanup all the workers

func HandleShutdown

func HandleShutdown(server *http.Server)

HandleShutdown - handles various shutdown signals

func InitSDK

func InitSDK(clientJSON string) error

func InvalidRequest

func InvalidRequest(msg string) error

InvalidRequest - create error messages that are needed when validating request input

func JSONString

func JSONString(json map[string]interface{}, field string, required bool) (string, error)

JSONString - given a json map and a field return the string typed value * required indicates whether to throw an error if the field is not found

func MethodError

func MethodError(endpoint, method string) error

func PrintError

func PrintError(v ...interface{})

PrintError is to print error

func Respond

func Respond(w http.ResponseWriter, data interface{}, err error)

Respond - respond either data or error as a response

func SetupCORSResponse

func SetupCORSResponse(w http.ResponseWriter, r *http.Request)

func SetupRootContext

func SetupRootContext(ctx context.Context)

SetupRootContext - sets up the root context that can be used to shutdown the node

func SplitArgs

func SplitArgs(args string) []string

SplitArgs split args into slice, and remove if item is empty

func ValidateClientDetails

func ValidateClientDetails(allocation, clientJSON string) error

func WithUserRateLimit

func WithUserRateLimit(h http.Handler) http.Handler

WithUserRateLimit - rate limiting for end user handlers

Types

type Error

type Error struct {
	Code string `json:"code,omitempty"`
	Msg  string `json:"msg"`
}

Error type for a new application error

func NewError

func NewError(code string, msg string) *Error

NewError - create a new error

func (*Error) Error

func (err *Error) Error() string

type JSONReqResponderF

type JSONReqResponderF func(ctx context.Context, json map[string]interface{}) (interface{}, error)

JSONReqResponderF - a handler that takes a JSON request and responds with a json response * Useful for GET operation where the input is coming via url parameters

type JSONResponderF

type JSONResponderF func(ctx context.Context, r *http.Request) (interface{}, error)

JSONResponderF - a handler that takes standard request (non-json) and responds with a json response * Useful for POST opertaion where the input is posted as json with * Content-type: application/json * header

type ReqRespHandlerf

type ReqRespHandlerf func(w http.ResponseWriter, r *http.Request)

ReqRespHandlerf - a type for the default hanlder signature

func ToFileResponse

func ToFileResponse(handler JSONResponderF) ReqRespHandlerf

ToFileResponse to give file as response

func ToJSONReqResponse

func ToJSONReqResponse(handler JSONReqResponderF) ReqRespHandlerf

ToJSONReqResponse - An adapter that takes a handler of the form * func AHandler(json map[string]interface{}) (interface{}, error) * which takes a parsed json map from the request, processes and returns an object or an error * and converts into a standard request/response handler

func ToJSONResponse

func ToJSONResponse(handler JSONResponderF) ReqRespHandlerf

ToJSONResponse - An adapter that takes a handler of the form * func AHandler(r *http.Request) (interface{}, error) * which takes a request object, processes and returns an object or an error * and converts into a standard request/response handler

func ToStreamResponse

func ToStreamResponse(handler StreamResponderF) ReqRespHandlerf

ToStreamResponse to give stream as response

func UserRateLimit

func UserRateLimit(handler ReqRespHandlerf) ReqRespHandlerf

UserRateLimit - rate limiting for end user handlers

type StatusBar

type StatusBar struct {
	Wait    *sync.WaitGroup
	Success bool
	Err     error
	// contains filtered or unexported fields
}

StatusBar is to check status of any operation

func (*StatusBar) CommitMetaCompleted

func (s *StatusBar) CommitMetaCompleted(request, response string, err error)

CommitMetaCompleted when commit meta completes

func (*StatusBar) Completed

func (s *StatusBar) Completed(allocationID, filePath string, filename string, mimetype string, size int, op int)

Completed for statusBar

func (*StatusBar) Error

func (s *StatusBar) Error(allocationID string, filePath string, op int, err error)

Error for statusBar

func (*StatusBar) InProgress

func (s *StatusBar) InProgress(allocationID, filePath string, op int, completedBytes int, bytes []byte)

InProgress for statusBar

func (*StatusBar) RepairCompleted

func (s *StatusBar) RepairCompleted(filesRepaired int)

RepairCompleted when repair is completed

func (*StatusBar) Started

func (s *StatusBar) Started(allocationID, filePath string, op int, totalBytes int)

Started for statusBar

type StreamResponderF

type StreamResponderF func(w http.ResponseWriter, r *http.Request) (interface{}, error)

Jump to

Keyboard shortcuts

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