Documentation ¶
Overview ¶
Package resource provides some shared behaviour for resources, and basic CRUD and URL helpers.
Index ¶
- func AddUserSessionCookie(w *httptest.ResponseRecorder, r *http.Request, id int) error
- func SetupAuthorisation()
- func SetupTestDatabase(depth int) error
- func SetupView(depth int) error
- func ValidateBoolean(param interface{}) bool
- func ValidateFloat(param interface{}) float64
- func ValidateInt(param interface{}) int64
- func ValidateString(param interface{}) string
- func ValidateTime(param interface{}) time.Time
- type Base
- func (r *Base) CacheKey() string
- func (r *Base) Create(params map[string]string) (int64, error)
- func (r *Base) CreateURL() string
- func (r *Base) Destroy() error
- func (r *Base) DestroyURL() string
- func (r *Base) IndexURL() string
- func (r *Base) OwnedBy(uid int64) bool
- func (r *Base) PrimaryKey() string
- func (r *Base) PrimaryKeyValue() int64
- func (r *Base) PublicURL() string
- func (r *Base) Query() *query.Query
- func (r *Base) ResourceID() string
- func (r *Base) SelectName() string
- func (r *Base) SelectValue() string
- func (r *Base) ShowURL() string
- func (r *Base) String() string
- func (r *Base) Table() string
- func (r *Base) Update(params map[string]string) error
- func (r *Base) UpdateURL() string
- func (r *Base) ValidateParams(params map[string]string, allowed []string) map[string]string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddUserSessionCookie ¶
AddUserSessionCookie adds a new cookie for the given user on the incoming request, so that we can test authentication in handlers.
func SetupTestDatabase ¶
SetupTestDatabase sets up the database for all tests from the test config.
func ValidateBoolean ¶
func ValidateBoolean(param interface{}) bool
ValidateBoolean returns the bool value of param or false
func ValidateFloat ¶
func ValidateFloat(param interface{}) float64
ValidateFloat returns the float value of param or 0.0
func ValidateInt ¶
func ValidateInt(param interface{}) int64
ValidateInt returns the int value of param or 0
func ValidateString ¶
func ValidateString(param interface{}) string
ValidateString returns the string value of param or ""
func ValidateTime ¶
ValidateTime returns the time value of param or the zero value of time.Time
Types ¶
type Base ¶
type Base struct { // ID is the default primary key of the resource. ID int64 // CreatedAt stores the creation time of the resource. CreatedAt time.Time // UpdatedAt stores the last update time of the resource. UpdatedAt time.Time // TableName is used for database queries and urls. TableName string // KeyName is used for database queries as the primary key. KeyName string }
Base defines shared fields and behaviour for resources.
func (*Base) CacheKey ¶
CacheKey generates a cache key for this resource based on the TableName, ID and UpdatedAt
func (*Base) DestroyURL ¶
DestroyURL returns the destroy url for this model /table/id/destroy
func (*Base) PrimaryKey ¶
PrimaryKey returns the id for primary key by default - used by query
func (*Base) PrimaryKeyValue ¶
PrimaryKeyValue returns the unique id
func (*Base) PublicURL ¶
PublicURL returns the canonical url for showing this resource usually this will differ in using the name as a slug
func (*Base) ResourceID ¶
ResourceID returns a key unique to this resource (we use table).
func (*Base) SelectName ¶
SelectName returns our name for select menus
func (*Base) SelectValue ¶
SelectValue returns our value for select options