app

package
v0.0.0-...-8ba40cc Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTypeInternal = iota
	ErrorTypeService
	ErrorTypeAuth
)

Variables

View Source
var (
	ErrorProfileNotFound = errors.New("profile not found")
)
View Source
var (
	ErrorUserNotInContext = errors.New("no user in context")
)

Functions

This section is empty.

Types

type Article

type Article struct {
	Id          int       `json:"id"`
	Slug        string    `json:"slug"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	Body        string    `json:"body"`
	Created     time.Time `json:"created"`
	Updated     time.Time `json:"updated"`
	Author      Profile   `json:"author"`
}

Article represents a single article

func (Article) UpdateMap

func (a Article) UpdateMap() map[string]interface{}

UpdateMap returns map of fields to be updated. It sets only subset of fields that are allowed to be updated and set it if it contains non empty values.

type ArticleListFilter

type ArticleListFilter struct {
	CurrentUser *User // used for favorites and following filtering
	Author      *Profile
	Limit       uint64
	Offset      uint64
}

func NewArticleListFilter

func NewArticleListFilter() ArticleListFilter

NewArticleListFilter creates filter with default values

func (ArticleListFilter) Validate

func (f ArticleListFilter) Validate() error

type ArticleServiceConfig

type ArticleServiceConfig struct {
	Type   string `default:"postgres"`
	DSN    string `default:"postgres://postgres:postgres@postgres/conduit?sslmode=disable"`
	Secret string
}

ArticleServiceConfig describes configuration for ArticleService

type Error

type Error struct {
	Type ErrorType
	Err  error
}

func AuthError

func AuthError(err error) Error

func InternalError

func InternalError(err error) Error

func ServiceError

func ServiceError(err error) Error

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type ErrorType

type ErrorType int

func (ErrorType) String

func (et ErrorType) String() string

type Profile

type Profile struct {
	Id        int    `json:"id"`
	Name      string `json:"username"`
	Bio       string `json:"bio"`
	Image     string `json:"image"`     // base64 encoded
	Following bool   `json:"following"` // set for authenticated users
}

Profile is a public user info with restricted set of fields

func ProfileFromUser

func ProfileFromUser(u *User) *Profile

ProfileFromUser converts User type to Profile. It sets Following field to false because it must be calculated by caller.

type ProfileResponse

type ProfileResponse struct {
	Profile Profile `json:"profile"`
}

ProfileResponse is a structure returned in profile handlers

type User

type User struct {
	Id    int    `json:"id"`
	Name  string `json:"username"`
	Email string `json:"email"`
	Bio   string `json:"bio,omitempty"`

	// Image is base64-encoded user avatar
	Image string `json:"image,omitempty"`

	// Token is JWT returned by user register, login and update
	Token string `json:"token,omitempty"`

	PasswordHash string `json:"-"`
}

User represents a user User is identified by email and authenticated by JWT. Password is hidden by custom marshaller.

func UserFromContext

func UserFromContext(ctx context.Context) (*User, bool)

func (*User) NewContext

func (u *User) NewContext(ctx context.Context) context.Context

func (User) UpdateMap

func (u User) UpdateMap() map[string]interface{}

UpdateMap returns map of fields to be updated. It sets only subset of fields that are allowed to be updated and set it if it contains non empty values.

Jump to

Keyboard shortcuts

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