service

package
v0.0.0-...-ab77271 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2018 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package service handles all business logic with the models

Index

Constants

View Source
const Default = "default"

Default role

Variables

View Source
var (
	ErrBanned         = errors.New("banned")
	ErrThreadNotFound = errors.New("not-found")
	ErrBoardNotFound  = errors.New("not-found")
	ErrThreadLocked   = errors.New("locked")
)

Functions

func CreatePost

func CreatePost(auth Authorizator,
	s store.Store,
	user *model.User,
	data *CreatePostData) (*model.Post, error)

CreatePost creates a new post

func ExtractToken

func ExtractToken(headerValue string) (string, error)

ExtractToken extracts a token from it's bearer prefix and returns it's raw value. Returns an error if no valid token is found

func GenerateStorageID

func GenerateStorageID() string

GenerateMediaID generates a new media ID

Types

type Authenticator

type Authenticator interface {
	// AuthenticateToken authenticates a token and returns it's user
	AuthenticateToken(tokenString string) (*model.User, error)

	// CreateToken creates a new JWT token
	CreateToken(user *model.User) (string, error)
}

Authenticator handles all authentication roles

func NewAuthenticator

func NewAuthenticator(users UserGetter, secret []byte) Authenticator

NewAuthenticator creates a new Authenticator using the default implementation.

type Authorizator

type Authorizator interface {
	IsAuthorized(user *model.User, action string) bool
}

Authorizator determines if a user can perform an action or not

func NewAuthorizator

func NewAuthorizator(roles map[string][]string,
	inheritance map[string][]string) Authorizator

NewAuthorizator creates a new Authorizator

func NewAuthorizatorFromFile

func NewAuthorizatorFromFile(f io.Reader) (Authorizator, error)

NewAuthorizatorFromFile creates a new authorizator reading content from an existing permission file

type CreatePostData

type CreatePostData struct {
	Parent string `form:"parent"`
	Board  string `form:"board"`

	Name    string `form:"name"`
	Comment string `form:"comment"`
	Subject string `form:"subject"`

	User *model.User

	Medias []*CreatePostMediaData

	IP string
}

CreatePostRequest constains all post creation information necessary for the creation of a new post

type CreatePostMediaData

type CreatePostMediaData struct {
	Size int64
	Name string
	File io.Reader
}

CreatePostMediaRequest contains all media information for upload

type FilesystemStorage

type FilesystemStorage struct {
	// contains filtered or unexported fields
}

FilesystemStorage stores medias in the filesystem

func NewFilesystemStorage

func NewFilesystemStorage(path string) *FilesystemStorage

NewFilesystemStorage creates a new filesystem storage

func (*FilesystemStorage) Delete

func (s *FilesystemStorage) Delete(id string) error

Delete deletes a filesystem file by it's id

func (*FilesystemStorage) Upload

func (s *FilesystemStorage) Upload(r io.Reader) (string, error)

Upload uploads a file to the filesystem and return it's id

type PostingError

type PostingError struct {
	// contains filtered or unexported fields
}

func (*PostingError) Error

func (p *PostingError) Error() string

type Storage

type Storage interface {
	// Upload uploads a new file
	Upload(io.Reader) (string, error)
	// Delete deletes a file
	Delete(id string) error
}

Storage stores files somewhere

type UserGetter

type UserGetter interface {
	GetUser(username string) (*model.User, error)
}

UserGetter gets an user by their username

Jump to

Keyboard shortcuts

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