model

package module
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2016 License: MIT Imports: 4 Imported by: 3

README

Package model

An optional base model class and utilities. The package includes some basic fields and methods acting on those fields. The fields included are:

    type Model struct {
    	TableName string
    	KeyName   string
    	Id        int64
    	CreatedAt time.Time
    	UpdatedAt time.Time
    }
Usage

It can be included in models with:

type MyModel struct {
    model.Model
    ...

Utility subpackages are:

  • file - utilities for handling files
  • validate - utilities for validating field values

Documentation

Overview

Package model provides a class including Id, CreatedAt and UpdatedAt, and some utility functions, optionally include in your models

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanParams

func CleanParams(params map[string]string, allowed []string) map[string]string

CleanParams returns a params list cleaned of keys not in allowed list DEPRECATED - REMOVE AND REPLACE WITH params.Clean()

Types

type Model

type Model struct {
	// Id is the default primary key of the model
	Id int64

	// CreatedAt stores the creation time of the model and should not be changed after cretion
	CreatedAt time.Time

	// UpdatedAt stores the last update time of the model
	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
}

Model base class

func (*Model) CacheKey

func (m *Model) CacheKey() string

CacheKey generates a cache key for this model object, dependent on id and UpdatedAt should we generate a hash of this to ensure we fit in small key size?

func (*Model) Init

func (m *Model) Init()

Init sets up the model fields

func (*Model) OwnedBy

func (m *Model) OwnedBy(uid int64) bool

OwnedBy returns true if the user id passed in owns this model

func (*Model) PrimaryKey

func (m *Model) PrimaryKey() string

PrimaryKey returns the id for primary key by default - used by query

func (*Model) PrimaryKeyValue

func (m *Model) PrimaryKeyValue() int64

PrimaryKeyValue returns the unique id

func (*Model) SelectName

func (m *Model) SelectName() string

SelectName returns our name for select menus

func (*Model) SelectValue

func (m *Model) SelectValue() string

SelectValue returns our value for select options

func (*Model) String

func (m *Model) String() string

String returns a string representation of the model

func (*Model) Table

func (m *Model) Table() string

Table returns the table name for this object

func (*Model) ToSlug

func (m *Model) ToSlug(name string) string

ToSlug converts our name to something suitable for use on the web as part of a url

func (*Model) URLCreate

func (m *Model) URLCreate() string

URLCreate returns the create url for this model /table/create

func (*Model) URLDestroy

func (m *Model) URLDestroy() string

URLDestroy returns the destroy url for this model /table/id/destroy

func (*Model) URLIndex

func (m *Model) URLIndex() string

URLIndex returns the index url for this model - /table

func (*Model) URLShow

func (m *Model) URLShow() string

URLShow returns the show url for this model /table/id

func (*Model) URLUpdate

func (m *Model) URLUpdate() string

URLUpdate returns the update url for this model /table/id/update

Directories

Path Synopsis
Package validate provides methods for validating params passed from the database row as interface{} types
Package validate provides methods for validating params passed from the database row as interface{} types

Jump to

Keyboard shortcuts

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