nozzle

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Capco Google Cloud Platform Functions

Capco

Setup

Installation
  • Install with go get
go get -u github.com/capcodigital/gcpfunctions
  • Include in golang module
import github.com/capcodigital/gcpfunctions

Contributing

If you would like to contribute to any Capco Digital OSS projects please read:

Documentation

Index

Constants

View Source
const (
	// DuplicateError record in DB
	DuplicateError = 409

	// InternalError error (Default)
	InternalError = 500
)
View Source
const (
	//DEBUG level
	DEBUG = "DEBUG"

	//INFO level
	INFO = "INFO"

	//WARN level
	WARN = "WARN"

	//ERROR level
	ERROR = "ERROR"
)

Variables

This section is empty.

Functions

func AddRoute

func AddRoute(verb string, path string, handler Handler)

AddRoute adds a specific route to the router

func CreateID

func CreateID() uuid.UUID

CreateID returns a UUID

func Deserialize

func Deserialize(request Request, object interface{}) error

Deserialize JSON byte array to an object

func ExecuteTestRequest

func ExecuteTestRequest(t *testing.T, verb string, path string, body string, funcHandler Handler) (*http.Request, *httptest.ResponseRecorder)

ExecuteTestRequest against the test server

func GetTestRequest

func GetTestRequest(t *testing.T, verb string, path string, body string) (*http.Request, *httptest.ResponseRecorder)

GetTestRequest creates a request for execution

func Handle

func Handle(w http.ResponseWriter, object Entity, sql string, params ...interface{})

Handle processes a HTTP request

func HandleBadRequestErr

func HandleBadRequestErr(w http.ResponseWriter, err error)

HandleBadRequestErr handles a bad request from the client

func Map

func Map(entity Entity, row *sql.Row) error

Map maps the DB to an entity

func ReturnOne

func ReturnOne(entity Entity, sql string, args ...interface{}) error

ReturnOne returns one (and only one) entity from the DB

func RunSQL

func RunSQL(sql string, args ...interface{}) (*sql.Row, error)

RunSQL is used to add an entity to the database

func Serialize

func Serialize(data interface{}) ([]byte, error)

Serialize object to byte array

func Serve

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

Serve handle a request and using the router redirects the traffic

func WriteErrorToResponse

func WriteErrorToResponse(w http.ResponseWriter, code int)

WriteErrorToResponse writes in a consistent way

Types

type Entity

type Entity interface {
	Map(row *sql.Row) error
}

Entity is a class that represent an entry in the DB

type Error

type Error struct {
	Message string `json:"id"`
}

Error object used to pass back msg

type ErrorBody

type ErrorBody struct {
	Code        int    `json:"code"`
	Description string `json:"description"`
}

ErrorBody represents a structured error

type Handler

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

Handler is a delegate to concrete handler

type LogEntry

type LogEntry struct {
	Level   string            `json:"level"`
	Action  string            `json:"action"`
	Message string            `json:"message,omitempty"`
	Map     map[string]string `json:"data,omitempty"`
	Error   error             `json:"error,omitempty"`
}

LogEntry represents an entry to log with message

func (*LogEntry) ToString

func (entry *LogEntry) ToString() string

ToString converts an entry to well shaped JSON

type Request

type Request struct {
	Params map[string]string
	Body   []byte
}

Request is an abstract of the key request info

func GetRequest

func GetRequest(r *http.Request) (Request, error)

GetRequest from the HTTP request

type Response

type Response struct {
	Code    int
	Headers map[string]string
	Data    interface{}
}

Response is an abstract of the key response info

type Route

type Route struct {
	// contains filtered or unexported fields
}

Route to be matched for the url

func (*Route) LogData

func (route *Route) LogData() map[string]string

LogData for logging

Jump to

Keyboard shortcuts

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