kitty

package module
v0.0.0-...-bc92c42 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2018 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxBytesInRequestBody limits incoming request body size to avoid malicious attack
	MaxBytesInRequestBody int64 = 1024 * 10
)

Variables

View Source
var (

	// PostcodeRegex to match 2 parts of a valid UK postcode
	PostcodeRegex = regexp.MustCompile(`^([A-Z]{1,2}\d{1,2}[A-Z]?)\s*(\d[A-Z]{2})$`)
)

Functions

func APICreate

func APICreate(w http.ResponseWriter, r *http.Request, ds Datastore, dst interface{}) (err error)

APICreate will parse request body into dst

func AppContext

func AppContext(r *http.Request) context.Context

AppContext instantiate appengine context from request

func Cleanse

func Cleanse(text string) string

Cleanse returns cleansed and html escapedstring

func Delete

func Delete(ctx context.Context, ds Datastore) error

Delete will delete the record in DB

func DeleteWithParent

func DeleteWithParent(ctx context.Context, ds Datastore, parent Datastore) error

DeleteWithParent will delete the record with provided Parentin DB

func FieldNames

func FieldNames(ds interface{}) []string

FieldNames returns a slice of exported datastore field names

func FilterBy

func FilterBy(
	ctx context.Context,
	ds Datastore,
	dst interface{},
	offset, limit int,
	orderBy string,
	filtersBy ...Filter,
) (err error)

FilterBy will parse dst from datastore with fitlers and paging parameters

func FindAll

func FindAll(
	ctx context.Context,
	ds Datastore,
	dst interface{},
	offset, limit int,
	orderBy string,
) (err error)

FindAll will parse dst from datastore with paging parameters

func FindOne

func FindOne(
	ctx context.Context,
	ds Datastore,
	dst interface{},
) (err error)

FindOne will parse dst from datastore with uid of ds

func FormatPhoneE164

func FormatPhoneE164(phone string) (formatted string)

FormatPhoneE164 is a function to format phone number to be E164 specific format

func GetEnv

func GetEnv(key string) string

GetEnv returns requested key from environment or nil

func HasStringInSlice

func HasStringInSlice(elements []string, s string) bool

HasStringInSlice checks if string element is in slice

func Key

func Key(ctx context.Context, ds Datastore) (*datastore.Key, error)

Key will get or generate and return a datastore Key type

func KeyWithParent

func KeyWithParent(ctx context.Context, ds, parent Datastore) (*datastore.Key, error)

KeyWithParent will get or generate and return a datastore Key type with Parent entity

func MapKeys

func MapKeys(input map[string]interface{}) (keys []string)

MapKeys converts a map interface to slice of string keys

func MarshalStruct

func MarshalStruct(ds interface{}) (message string)

MarshalStruct renders JSON string of a struct instance

func MiddlewareAPIContentType

func MiddlewareAPIContentType(next http.Handler) http.Handler

MiddlewareAPIContentType limits requests with only json content-type

func MiddlewareMaxRequestBody

func MiddlewareMaxRequestBody(next http.Handler) http.Handler

MiddlewareMaxRequestBody limits request body to max size

func MiddlewareRecoverPanic

func MiddlewareRecoverPanic(h http.Handler) http.Handler

MiddlewareRecoverPanic middleware recovers any panic and email Admin for errors

func Notify

func Notify(ctx context.Context, title string, ds Datastore)

Notify is a function to send datatore interface summary and a short sentence to Notification channel or Bot

func NotifyAdmin

func NotifyAdmin(ctx context.Context, topic string, entity Datastore, errSource error)

NotifyAdmin send an email to designated admin so technical issues can be resolved

func Query

func Query(ds Datastore) *datastore.Query

Query will instantiate a new datastore query for given entity

func QueryFilter

func QueryFilter(
	query *datastore.Query,
	filtersBy ...Filter,
) (*datastore.Query, error)

QueryFilter will instantiate query with filters

func QueryPager

func QueryPager(
	query *datastore.Query,
	offset, limit int,
	orderBy string,
) *datastore.Query

QueryPager will instantiate query with paging parameters

func RenderJSON

func RenderJSON(w http.ResponseWriter, r *http.Request, code int, err error, data interface{})

RenderJSON renders standardised json response body

func Sanitise

func Sanitise(text string) string

Sanitise returns sanitised html string allowing safe string

func SanitiseInChunks

func SanitiseInChunks(texts []string) []string

SanitiseInChunks returns sanitised base64 encoded string allowing safe string in 1000 length for each chunk

func Save

func Save(ctx context.Context, ds Datastore) error

Save will save the Datastore type struct in datastore

func SaveWithParent

func SaveWithParent(ctx context.Context, ds Datastore, parent Datastore) error

SaveWithParent will save the Datastore type struct with Parent entity in datastore

func StructFromJSON

func StructFromJSON(i interface{}, fpath string)

StructFromJSON parse json file to struct instance

func StructToMap

func StructToMap(ds interface{}) map[string]interface{}

StructToMap converts struct to a map interface

func ToTitleCase

func ToTitleCase(input interface{}) string

ToTitleCase parse input to title cased string separated with single space

func ValidatePhone

func ValidatePhone(
	ctx context.Context,
	phone string,
	phoneTypes []string,
) error

ValidatePhone checks if mobile phone number can be used

func ValidateSchema

func ValidateSchema(ds Datastore) error

ValidateSchema for Datastore

func ValidateUID

func ValidateUID(uid string) error

ValidateUID checks if uid is in uuid.v4 format

Types

type App

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

App proxy with mux.Router and functions

func NewApp

func NewApp() *App

NewApp returns new Kitty App instance

func (*App) IsDevelopment

func (app *App) IsDevelopment() bool

IsDevelopment checks ENV environment variable

func (*App) IsProduction

func (app *App) IsProduction() bool

IsProduction checks ENV environment vairable

func (*App) Mount

func (app *App) Mount(router *mux.Router, path string)

Mount path to serve router

func (*App) Register404View

func (app *App) Register404View(router *mux.Router)

Register404View renders 404 view

func (*App) RegisterRedirect

func (app *App) RegisterRedirect(router *mux.Router, view, redirectURI string, redirectCode int)

RegisterRedirect registers the route and handle redirect

func (*App) RegisterView

func (app *App) RegisterView(router *mux.Router, view string)

RegisterView registers the route and handle view template rendering

func (*App) RenderTemplate

func (app *App) RenderTemplate(w http.ResponseWriter, name string) error

RenderTemplate renders base and content template

func (*App) SetData

func (app *App) SetData(data interface{})

SetData set data on Router instance

func (*App) Static

func (app *App) Static(router *mux.Router, prefix, dir string)

Static serves static over prefix path

func (*App) Use

func (app *App) Use(router *mux.Router, mw func(http.Handler) http.Handler)

Use middleware proxy to mux.Router

type BaseModel

type BaseModel struct {
	UID     string    `valid:",optional,uuidv4"`
	Created time.Time `valid:"-"`
	Updated time.Time `valid:"-"`
}

BaseModel is a base struct for embedding fields and methods

func (*BaseModel) AfterSave

func (ds *BaseModel) AfterSave(context.Context)

AfterSave for BaseModel (to override)

func (*BaseModel) BeforeCreate

func (ds *BaseModel) BeforeCreate(context.Context) error

BeforeCreate for BaseModel (to override)

func (*BaseModel) BeforeSave

func (ds *BaseModel) BeforeSave(context.Context) error

BeforeSave for BaseModel (to override)

func (*BaseModel) GetID

func (ds *BaseModel) GetID() string

GetID for BaseModel

func (*BaseModel) SetID

func (ds *BaseModel) SetID(uid string)

SetID for BaseModel

func (*BaseModel) String

func (ds *BaseModel) String() string

String for BaseModel (to override)

func (*BaseModel) Summary

func (ds *BaseModel) Summary() string

Summary for BaseModel (to override)

func (*BaseModel) Validate

func (ds *BaseModel) Validate() error

Validate for BaseModel (to override)

type Datastore

type Datastore interface {
	GetID() string
	SetID(string)
	BeforeCreate(context.Context) error
	BeforeSave(context.Context) error
	AfterSave(context.Context)
	Validate() error
	String() string
	Summary() string
}

Datastore is an interface for appengine datastore to populate key and save

type EntityInstance

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

EntityInstance struct ...

func NewEntity

func NewEntity() *EntityInstance

NewEntity instantiate Entity instance

func (*EntityInstance) GenerateAPI

func (entity *EntityInstance) GenerateAPI(
	destPath, packageName, modelPath, modelPackageName string,
) error

GenerateAPI auto generates API CRUD ops to given path folder

func (*EntityInstance) Register

func (entity *EntityInstance) Register(kind string)

Register a datastore entity name to instance

type Filter

type Filter struct {
	Key   string
	Value interface{}
}

Filter ...

func RequestFilter

func RequestFilter(r *http.Request, ds Datastore) (
	offset, limit int,
	orderBy string,
	filtersBy []Filter,
)

RequestFilter parse querystring from request and return as filters

type Template

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

Template is a struct proxy to all available templates

type Templates

type Templates map[string]*template.Template

Templates store named and parsed template within map

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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