morningpost

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 28 Imported by: 0

README

The Morning Post

It's nice to have something interesting to read with your morning coffee. My task with this project is to write a Go program that will curate a little “morning newspaper” for you.

Demo Video

Getting started

Running program

If you have Go installed and configured on your machine, you can run it:

$ go run github.com/thiagonache/morningpost/cmd/morningpost@latest
go: downloading github.com/thiagonache/morningpost v0.0.9-alpha
Listening at http://127.0.0.1:33000

Alternatively, you can download the compiled binary from the releases page.

Skills demonstrated

Go Backend developer
  • Concurrency
  • Web API
  • Web Client
  • Functional Programming
  • Interfaces
  • Simple Store
  • Crawler
  • SQL Database adapter
  • NoSQL Database adapter
  • AI recommendation system integration
Go Frontend developer
  • HTMX
  • HTML
  • CSS
  • AJAX
  • Server side templating
CICD
  • Auto release
  • Unit tests
  • Integration tests
  • End to End tests
  • UI tests
  • Build container image
  • Code dependencies vulnerability check
  • Deploy solution on two cloud providers

Documentation

Visit our documentation page

Documentation

Index

Constants

View Source
const (
	DefaultHTTPTimeout   = 30 * time.Second
	DefaultListenAddress = "127.0.0.1:33000"
	DefaultNewsPageSize  = 10
	FeedTypeAtom         = "Atom"
	FeedTypeRDF          = "RDF"
	FeedTypeRSS          = "RSS"
)

Variables

This section is empty.

Functions

func Main

func Main() int

func ParseFeedType

func ParseFeedType(r io.Reader) (string, error)

func RenderHTMLTemplate

func RenderHTMLTemplate(w io.Writer, templatePath string, data any) error

func RunServer

func RunServer(store Store, stdout, stderr io.Writer, args ...string) error

Types

type Feed

type Feed struct {
	Endpoint string
	ID       uint64
	Type     string
}

func ParseLinkTags

func ParseLinkTags(r io.Reader, baseURL string) ([]Feed, error)

func (Feed) GetNews

func (f Feed) GetNews() ([]News, error)

type FileStore

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

func NewFileStore

func NewFileStore(opts ...FileStoreOption) (*FileStore, error)

func (*FileStore) Add

func (f *FileStore) Add(feeds ...Feed)

func (*FileStore) Delete

func (f *FileStore) Delete(id uint64)

func (*FileStore) GetAll

func (f *FileStore) GetAll() []Feed

func (*FileStore) Load

func (f *FileStore) Load() error

func (*FileStore) Path

func (f *FileStore) Path() string

func (*FileStore) Save

func (f *FileStore) Save() error

type FileStoreOption

type FileStoreOption func(*FileStore)

func WithFileStorePath

func WithFileStorePath(path string) FileStoreOption

type MorningPost

type MorningPost struct {
	Client *http.Client

	ListenAddress string
	NewsPageSize  int
	PageNews      []News
	Stderr        io.Writer
	Stdout        io.Writer

	Store Store

	News []News
	// contains filtered or unexported fields
}

func New

func New(store Store, opts ...Option) (*MorningPost, error)

func (*MorningPost) AddNews

func (m *MorningPost) AddNews(news []News)

func (*MorningPost) EmptyNews

func (m *MorningPost) EmptyNews()

func (*MorningPost) FindFeeds

func (m *MorningPost) FindFeeds(URL string) []Feed

func (*MorningPost) GetNews

func (m *MorningPost) GetNews() error

func (*MorningPost) HandleFeeds

func (m *MorningPost) HandleFeeds(w http.ResponseWriter, r *http.Request)

func (*MorningPost) HandleFeedsDelete

func (m *MorningPost) HandleFeedsDelete(w http.ResponseWriter, r *http.Request)

func (*MorningPost) HandleFeedsTableRows

func (m *MorningPost) HandleFeedsTableRows(w http.ResponseWriter, r *http.Request)

func (*MorningPost) HandleNews

func (m *MorningPost) HandleNews(w http.ResponseWriter, r *http.Request)

func (*MorningPost) HandleNewsTableRows

func (m *MorningPost) HandleNewsTableRows(w http.ResponseWriter, r *http.Request)

func (*MorningPost) ListenAndServe

func (m *MorningPost) ListenAndServe() error

func (*MorningPost) RandomNews

func (m *MorningPost) RandomNews()

func (*MorningPost) Serve

func (m *MorningPost) Serve(l net.Listener) error

func (*MorningPost) Shutdown

func (m *MorningPost) Shutdown() error

func (*MorningPost) WaitForExit

func (m *MorningPost) WaitForExit() error

type News

type News struct {
	Feed  string
	Title string
	URL   string
}

func NewNews

func NewNews(feed, title, URL string) (News, error)

func ParseAtomResponse

func ParseAtomResponse(r io.Reader) ([]News, error)

func ParseRDFResponse

func ParseRDFResponse(r io.Reader) ([]News, error)

func ParseRSSResponse

func ParseRSSResponse(r io.Reader) ([]News, error)

type Option

type Option func(*MorningPost) error

func FromArgs

func FromArgs(args []string) Option

func WithClient

func WithClient(c *http.Client) Option

func WithStderr

func WithStderr(w io.Writer) Option

func WithStdout

func WithStdout(w io.Writer) Option

type Store

type Store interface {
	Add(...Feed)
	Delete(uint64)
	GetAll() []Feed
	Save() error
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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