domain

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package domain contains domain entities and core validation rules.

Index

Constants

View Source
const (
	ContentLibrary = "library"
	ContentLink    = "link"
	ContentVideo   = "video"
)

Common content types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Meta

type Meta struct {
	// Name represents a unique name/identifier for the object.
	Name string `json:"name" bson:"name"`

	// Tags can contain additional metadata about the object.
	Tags []string `json:"tags,omitempty" bson:"tags"`

	// CreateAt represents the time at which this object was created.
	CreatedAt time.Time `json:"created_at,omitempty" bson:"created_at"`

	// UpdatedAt represents the time at which this object was last
	// modified.
	UpdatedAt time.Time `json:"updated_at,omitempty" bson:"updated_at"`
}

Meta represents metadata about different entities.

func (*Meta) SetDefaults

func (meta *Meta) SetDefaults()

SetDefaults sets sensible defaults on meta.

func (Meta) Validate

func (meta Meta) Validate() error

Validate performs basic validation of the metadata.

type Post

type Post struct {
	Meta `json:",inline" bson:",inline"`

	// Type should state the type of the content. (e.g., library,
	// video, link etc.)
	Type string `json:"type" bson:"type"`

	// Body should contain the actual content according to the Type
	// specified. (e.g. github.com/spy16/parens when Type=link)
	Body string `json:"body" bson:"body"`

	// Owner represents the name of the user who created the post.
	Owner string `json:"owner" bson:"owner"`
}

Post represents an article, link, video etc.

func (Post) Validate

func (post Post) Validate() error

Validate performs validation of the post.

type User

type User struct {
	Meta `json:",inline,omitempty" bson:",inline"`

	// Email should contain a valid email of the user.
	Email string `json:"email,omitempty" bson:"email"`

	// Secret represents the user secret.
	Secret string `json:"secret,omitempty" bson:"secret"`
}

User represents information about registered users.

func (User) CheckSecret

func (user User) CheckSecret(password string) bool

CheckSecret compares the cleartext password with the hash.

func (*User) HashSecret

func (user *User) HashSecret() error

HashSecret creates bcrypt hash of the password.

func (User) Validate

func (user User) Validate() error

Validate performs basic validation of user information.

Jump to

Keyboard shortcuts

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