Documentation
¶
Index ¶
- Constants
- Variables
- func APICreate(w http.ResponseWriter, r *http.Request, ds Datastore, dst interface{}) (err error)
- func AppContext(r *http.Request) context.Context
- func Cleanse(text string) string
- func Delete(ctx context.Context, ds Datastore) error
- func DeleteWithParent(ctx context.Context, ds Datastore, parent Datastore) error
- func FieldNames(ds interface{}) []string
- func FilterBy(ctx context.Context, ds Datastore, dst interface{}, offset, limit int, ...) (err error)
- func FindAll(ctx context.Context, ds Datastore, dst interface{}, offset, limit int, ...) (err error)
- func FindOne(ctx context.Context, ds Datastore, dst interface{}) (err error)
- func FormatPhoneE164(phone string) (formatted string)
- func GetEnv(key string) string
- func HasStringInSlice(elements []string, s string) bool
- func Key(ctx context.Context, ds Datastore) (*datastore.Key, error)
- func KeyWithParent(ctx context.Context, ds, parent Datastore) (*datastore.Key, error)
- func MapKeys(input map[string]interface{}) (keys []string)
- func MarshalStruct(ds interface{}) (message string)
- func MiddlewareAPIContentType(next http.Handler) http.Handler
- func MiddlewareMaxRequestBody(next http.Handler) http.Handler
- func MiddlewareRecoverPanic(h http.Handler) http.Handler
- func Notify(ctx context.Context, title string, ds Datastore)
- func NotifyAdmin(ctx context.Context, topic string, entity Datastore, errSource error)
- func Query(ds Datastore) *datastore.Query
- func QueryFilter(query *datastore.Query, filtersBy ...Filter) (*datastore.Query, error)
- func QueryPager(query *datastore.Query, offset, limit int, orderBy string) *datastore.Query
- func RenderJSON(w http.ResponseWriter, r *http.Request, code int, err error, data interface{})
- func Sanitise(text string) string
- func SanitiseInChunks(texts []string) []string
- func Save(ctx context.Context, ds Datastore) error
- func SaveWithParent(ctx context.Context, ds Datastore, parent Datastore) error
- func StructFromJSON(i interface{}, fpath string)
- func StructToMap(ds interface{}) map[string]interface{}
- func ToTitleCase(input interface{}) string
- func ValidatePhone(ctx context.Context, phone string, phoneTypes []string) error
- func ValidateSchema(ds Datastore) error
- func ValidateUID(uid string) error
- type App
- func (app *App) IsDevelopment() bool
- func (app *App) IsProduction() bool
- func (app *App) Mount(router *mux.Router, path string)
- func (app *App) Register404View(router *mux.Router)
- func (app *App) RegisterRedirect(router *mux.Router, view, redirectURI string, redirectCode int)
- func (app *App) RegisterView(router *mux.Router, view string)
- func (app *App) RenderTemplate(w http.ResponseWriter, name string) error
- func (app *App) SetData(data interface{})
- func (app *App) Static(router *mux.Router, prefix, dir string)
- func (app *App) Use(router *mux.Router, mw func(http.Handler) http.Handler)
- type BaseModel
- func (ds *BaseModel) AfterSave(context.Context)
- func (ds *BaseModel) BeforeCreate(context.Context) error
- func (ds *BaseModel) BeforeSave(context.Context) error
- func (ds *BaseModel) GetID() string
- func (ds *BaseModel) SetID(uid string)
- func (ds *BaseModel) String() string
- func (ds *BaseModel) Summary() string
- func (ds *BaseModel) Validate() error
- type Datastore
- type EntityInstance
- type Filter
- type Template
- type Templates
Constants ¶
const ( // MaxBytesInRequestBody limits incoming request body size to avoid malicious attack MaxBytesInRequestBody int64 = 1024 * 10 )
Variables ¶
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 AppContext ¶
AppContext instantiate appengine context from request
func DeleteWithParent ¶
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 FormatPhoneE164 ¶
FormatPhoneE164 is a function to format phone number to be E164 specific format
func HasStringInSlice ¶
HasStringInSlice checks if string element is in slice
func KeyWithParent ¶
KeyWithParent will get or generate and return a datastore Key type with Parent entity
func MarshalStruct ¶
func MarshalStruct(ds interface{}) (message string)
MarshalStruct renders JSON string of a struct instance
func MiddlewareAPIContentType ¶
MiddlewareAPIContentType limits requests with only json content-type
func MiddlewareMaxRequestBody ¶
MiddlewareMaxRequestBody limits request body to max size
func MiddlewareRecoverPanic ¶
MiddlewareRecoverPanic middleware recovers any panic and email Admin for errors
func Notify ¶
Notify is a function to send datatore interface summary and a short sentence to Notification channel or Bot
func NotifyAdmin ¶
NotifyAdmin send an email to designated admin so technical issues can be resolved
func QueryFilter ¶
QueryFilter will instantiate query with filters
func QueryPager ¶
QueryPager will instantiate query with paging parameters
func RenderJSON ¶
RenderJSON renders standardised json response body
func SanitiseInChunks ¶
SanitiseInChunks returns sanitised base64 encoded string allowing safe string in 1000 length for each chunk
func SaveWithParent ¶
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 ¶
ValidatePhone checks if mobile phone number can be used
func ValidateUID ¶
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 (*App) IsDevelopment ¶
IsDevelopment checks ENV environment variable
func (*App) IsProduction ¶
IsProduction checks ENV environment vairable
func (*App) Register404View ¶
Register404View renders 404 view
func (*App) RegisterRedirect ¶
RegisterRedirect registers the route and handle redirect
func (*App) RegisterView ¶
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
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) BeforeCreate ¶
BeforeCreate for BaseModel (to override)
func (*BaseModel) BeforeSave ¶
BeforeSave 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 (*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