common

package
v0.1.1-0...-99c9eb7 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2017 License: BSD-3-Clause Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RegexpValidateEmailAddress = regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)

RegexpValidateEmailAddress is just a very simple regular expression to catch 99% of user input mistakes. Email addresses in the system are always validated by actually sending a verification email to it.

View Source
var RegexpValidatePostalcode = regexp.MustCompile(`^[0-9]{4} ?[a-zA-Z]{2}$`)

RegexpValidatePostalcode can be used to validate a dutch postalcode (e.g. `1234AB`)

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	ID     uint64   `json:"id,omitempty"`
	Errors []string `json:"errors"`
}

APIResponse is used by insert/update/delete methods to indicate to the frontend whether the operation was successful. When marshalled to JSON it will give the front-end an array of errors, length 0 indicating all went fine. And optionally the ID of a created object.

func NewAPIResponse

func NewAPIResponse() APIResponse

NewAPIResponse creates a new emptry API response.

func (*APIResponse) AddErrorCode

func (cr *APIResponse) AddErrorCode(err string)

AddErrorCode adds an error code to the APIResponse

func (*APIResponse) CheckPgErr

func (cr *APIResponse) CheckPgErr(err error) bool

CheckPgErr checks an error. If it's a postgres error of a kind that is handled in the front-end, an error code is added to the API response object and the function returns true. TODO: accept a whitelist of database constraints and violations that can go through to the frontend.

type Date

type Date struct {
	Year  uint64 `json:"year"`
	Month uint64 `json:"month"`
	Day   uint64 `json:"day"`
}

Date implements the sql.Scanner and sql.Valuer interfaces. It converts from date strings following the format `yyyy-mm-dd`.

func (*Date) Scan

func (d *Date) Scan(value interface{}) error

Scan reads a date string into the Date format. The scanner does not validate that given datestring contains a valid date.

func (Date) Value

func (d Date) Value() (driver.Value, error)

Value transforms Date into a date-string which can be easily converted by postgress to a date type.

Jump to

Keyboard shortcuts

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