app

package
v0.0.0-...-7b36f56 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Must

func Must(err error)

func NewDB

func NewDB(log *zap.Logger, cfg *Config) (*pg.DB, error)

func NewLog

func NewLog(cnf *Config) (*zap.Logger, error)

func NewResponseError

func NewResponseError(statusCode int, message string) error

Types

type ActionError

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

func (*ActionError) Error

func (err *ActionError) Error() string

func (*ActionError) IsNotFound

func (err *ActionError) IsNotFound() bool

type Actions

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

func NewActions

func NewActions(log *zap.Logger, db *pg.DB) (*Actions, error)

func (*Actions) GetAllChannels

func (a *Actions) GetAllChannels() ([]Channel, *ActionError)

func (*Actions) GetChannelById

func (a *Actions) GetChannelById(id uuid.UUID) (*Channel, *ActionError)

func (*Actions) GetPostById

func (a *Actions) GetPostById(id uuid.UUID) (*Post, *ActionError)

func (*Actions) GetPostsByChannelOrdered

func (a *Actions) GetPostsByChannelOrdered(channelId uuid.UUID, page, pageSize int) ([]Post, *ActionError)

page - page to get. starts from 0 pageSize - limit of posts to get.

func (*Actions) GetPostsByTitle

func (a *Actions) GetPostsByTitle(title string, page, pageSize int) ([]Post, *ActionError)

func (*Actions) GetPostsOrdered

func (a *Actions) GetPostsOrdered(page, pageSize int) ([]Post, *ActionError)

page - page to get. starts from 0 pageSize - limit of posts to get.

func (*Actions) SyncChannel

func (a *Actions) SyncChannel(channel Channel) *ActionError

func (*Actions) SyncPost

func (a *Actions) SyncPost(channel *Channel, post *Post, guid string) *ActionError

type ApiConfig

type ApiConfig struct {
	Listen string
}

type Channel

type Channel struct {
	Id          uuid.UUID `sql:",pk,type:uuid"`
	Title       string    `pg:",notnull"`
	Image       string
	Description string
}

Channel is model representing RSS channel.

type Config

type Config struct {
	AppName     string
	Environment Environment
	Logger      LoggerConfig
	Database    DatabaseConfig
	Api         ApiConfig
	Import      []ImportChannelConfig
}

func NewConfig

func NewConfig(configPath, appName string) (*Config, error)

type DatabaseConfig

type DatabaseConfig struct {
	User     string
	Password string
	Database string
	Address  string
}

type Environment

type Environment string
const (
	EnvDevelopment Environment = "Development"
	EnvProduction  Environment = "Production"
)

type Flags

type Flags struct {
	ConfigPath string
	ShowHelp   bool
}

func NewFlags

func NewFlags() *Flags

type ImportChannelConfig

type ImportChannelConfig struct {
	Address string
	Id      uuid.UUID
}

type LoggerConfig

type LoggerConfig struct {
	Dir string
}

type Post

type Post struct {
	Id              uuid.UUID `sql:",pk,type:uuid"`
	ChannelId       uuid.UUID
	Channel         *Channel  `pg:"rel:has-one"`
	PublicationDate time.Time `pg:",notnull"` // +order key compose index
	Title           string    `pg:",notnull"` // +tsvector index
	Image           string
	Link            string
	Description     string `pg:",notnull"`
}

Post is model representing RSS item.

type RequestContext

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

func (*RequestContext) AnswerBadRequest

func (ctx *RequestContext) AnswerBadRequest(msg string) error

func (*RequestContext) AnswerInternalError

func (ctx *RequestContext) AnswerInternalError(msg string) error

func (*RequestContext) AnswerJson

func (ctx *RequestContext) AnswerJson(value interface{}) error

func (*RequestContext) AnswerNotFound

func (ctx *RequestContext) AnswerNotFound(msg string) error

func (*RequestContext) IntQueryParam

func (ctx *RequestContext) IntQueryParam(name string) (res int, err error)

IntQueryParam returns parsed int from request query params. name - query variable name.

func (*RequestContext) StringQueryParam

func (ctx *RequestContext) StringQueryParam(name string) (res string, err error)

StringQueryParam returns string from request query params. name - query variable name.

func (*RequestContext) UuidParam

func (ctx *RequestContext) UuidParam(name string) (res uuid.UUID, err error)

UuidParam returns parsed id in UUID format from request uri. name - uri context variable name.

func (*RequestContext) WrapActionsError

func (ctx *RequestContext) WrapActionsError(err *ActionError) error

type ResponseError

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

func (*ResponseError) Error

func (e *ResponseError) Error() string

type ResponseErrorM

type ResponseErrorM struct {
	Error string `json:"error"`
}

type RssPostId

type RssPostId struct {
	Guid      string    `pg:",notnull"`
	ChannelId uuid.UUID `sql:",type:uuid"`
	Channel   *Channel  `pg:"rel:has-one"`
	PostId    uuid.UUID `sql:",type:uuid"`
	Post      *Post     `pg:"rel:has-one"`
}

RssPostId is model of mapping guid from RSS item to PostId

type Server

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

func NewServer

func NewServer(log *zap.Logger, cfg *Config) *Server

Creates empty HTTP server, not runs it.

func (*Server) Get

func (srv *Server) Get(path string, handler func(c RequestContext) error)

func (*Server) Run

func (srv *Server) Run()

Run HTTP server.

Jump to

Keyboard shortcuts

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