Documentation ¶
Overview ¶
Package service provides methods to work with pastes and users. Methods of this package do not log or print out anything, they return errors instead. It is up to the user of the Service to handle the errors and provide useful information to the end user.
Index ¶
- Variables
- type PasteRequest
- type Service
- func (s Service) GetCount() (pastes, users int64)
- func (s Service) GetOrUpdateUser(usr store.User) (store.User, error)
- func (s Service) GetPaste(url string, uid string, pwd string) (store.Paste, error)
- func (s Service) NewPaste(pr PasteRequest) (store.Paste, error)
- func (s Service) UserPastes(uid string) ([]store.Paste, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrPasteNotFound = errors.New("paste not found") ErrUserNotFound = errors.New("user not found") ErrPasteIsPrivate = errors.New("paste is private") ErrPasteHasPassword = errors.New("paste has password") ErrWrongPassword = errors.New("paste password is incorrect") ErrStoreFailure = errors.New("store opertation failed") ErrEmptyBody = errors.New("body is empty") ErrWrongPrivacy = errors.New("privacy is wrong") ErrWrongDuration = errors.New("wrong duration format") )
ErrPasteNotFound and other common errors.
Functions ¶
This section is empty.
Types ¶
type PasteRequest ¶
type PasteRequest struct { Title string `json:"title" form:"title"` Body string `json:"body" form:"body" binding:"required"` Expires string `json:"expires" form:"expires" binding:"required"` DeleteAfterRead bool `json:"delete_after_read" form:"delete_after_read" binding:"-"` Privacy string `json:"privacy" form:"privacy" binding:"required"` Password string `json:"password" form:"password"` Syntax string `json:"syntax" form:"syntax" binding:"required"` UserID string `json:"user_id"` }
PasteRequest is an input to Create method, normally comes from a web form.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service type provides method to work with pastes and users.
func NewWithMemDB ¶
func NewWithMemDB() *Service
NewWithMemDB returns new Service with memory as a store.
func NewWithPostgres ¶
NewWithPostgres returns new Service with postgres db as a store.
func (Service) GetOrUpdateUser ¶
GetOrUpdateUser saves the user in the store and returns it.
func (Service) GetPaste ¶
GetPaste returns a paste given encoded URL. If the paste is private GetPaste will check that it belongs to the user with provided uid. If password is given and the paste has password GetPaste will check that the password is correct.
func (Service) NewPaste ¶
func (s Service) NewPaste(pr PasteRequest) (store.Paste, error)
NewPaste creates new Paste from the request and saves it in the store. Paste.Body is mandatory, Paste.Expires is default to never, Paste.Privacy must be on of ["private","public","unlisted"]. If password is provided it is stored as a hash.