helper

package
v0.0.0-...-eac6ddc Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const BADLY_FORMATTED_JSON string = "Request body contains badly-formed JSON"
View Source
const (
	EMPTY = ""
)
View Source
const MAX_REQUEST_READ_SIZE int64 = 1048576
View Source
const REQUEST_BODY_MUST_NOT_BE_EMPTY string = "Request body must not be empty"
View Source
const RESPONSE_BODY_MUST_NOT_BE_LARGER_THAN_1MB string = "Request body must not be larger than 1MB"

Variables

This section is empty.

Functions

func ConnectToDatabase

func ConnectToDatabase(ctx context.Context, params *DatabaseConnectionParams, log *zap.Logger, models ...interface{}) (*core_database.DatabaseConn, error)

ConnectToDatabase establish and connects to a database instance

func CreateRequestBody

func CreateRequestBody(body interface{}) (*bytes.Reader, error)

CreateRequestBody creates a request object to be used in an http call

func DecodeJSONBody

func DecodeJSONBody(w http.ResponseWriter, r *http.Request, dst interface{}) error

DecodeJSONBody decodes a request body in json form and returns a malformed request error type if any errors do occur

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, error string, code int)

func ExtractIDFromRequest

func ExtractIDFromRequest(r *http.Request) (uint64, error)

ExtractIDFromRequest takes as input a request object and extracts an id from it

func ExtractStripeConnectedAccountIdFromRequest

func ExtractStripeConnectedAccountIdFromRequest(r *http.Request) (string, error)

ExtractStripeConnectedAccountIdFromRequest extracts a stripe connected account Id from a connected object

func GenerateRandomString

func GenerateRandomString(n int) string

GenerateRandomString generates a random string based on the size specified by the client

func IsEmpty

func IsEmpty(field string) bool

func JSONResponse

func JSONResponse(w http.ResponseWriter, result interface{})

func JSONResponseCode

func JSONResponseCode(w http.ResponseWriter, result interface{}, responseCode int)

Types

type DatabaseConnectionParams

type DatabaseConnectionParams struct {
	Host         string
	User         string
	Password     string
	DatabaseName string
	Port         int
}

type MalformedRequest

type MalformedRequest struct {
	Status int
	Msg    string
}

MalformedRequest is a custom error type

func (*MalformedRequest) Error

func (mr *MalformedRequest) Error() string

Jump to

Keyboard shortcuts

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