peapod

package module
v0.0.0-...-6e9cc21 Latest Latest
Warning

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

Go to latest
Published: May 6, 2017 License: MIT Imports: 10 Imported by: 0

README

peapod

Peapod is a service for hosting personal podcast feeds. It allows users to send URLs via SMS to the service and, in return, receive a personal feed URL that they can subscribe to.

Documentation

Index

Constants

View Source
const (
	ErrInternal     = Error("internal error")
	ErrUnauthorized = Error("unauthorized")
)

General errors.

View Source
const (
	ErrFilenameRequired = Error("filename required")
	ErrInvalidFilename  = Error("invalid filename")
)

File errors

View Source
const (
	ErrJobRequired      = Error("job required")
	ErrJobNotFound      = Error("job not found")
	ErrJobOwnerRequired = Error("job owner required")
	ErrJobOwnerNotFound = Error("job owner not found")
	ErrInvalidJobType   = Error("invalid job type")
	ErrInvalidJobStatus = Error("invalid job status")
)

Job errors.

View Source
const (
	JobTypeCreateTrackFromURL = "create_track_from_url"
	JobTypeCreateTrackFromTTS = "create_track_from_tts"
)

Job types.

View Source
const (
	JobStatusPending    = "pending"
	JobStatusProcessing = "processing"
	JobStatusCompleted  = "completed"
	JobStatusFailed     = "failed"
)

Job statuses.

View Source
const (
	ErrPlaylistRequired      = Error("playlist required")
	ErrPlaylistNotFound      = Error("playlist not found")
	ErrPlaylistOwnerRequired = Error("playlist owner required")
	ErrPlaylistTokenRequired = Error("playlist token required")
	ErrPlaylistNameRequired  = Error("playlist name required")
)

Playlist errors.

View Source
const (
	ErrTrackRequired         = Error("track required")
	ErrTrackNotFound         = Error("track not found")
	ErrTrackPlaylistRequired = Error("track playlist required")
	ErrTrackFilenameRequired = Error("track filename required")
	ErrTrackTitleRequired    = Error("track title required")
)

Track errors.

View Source
const (
	ErrUserRequired             = Error("user required")
	ErrUserNotFound             = Error("user not found")
	ErrUserMobileNumberInUse    = Error("mobile number already in use")
	ErrUserMobileNumberRequired = Error("mobile number required")
)

User errors.

View Source
const DefaultPlaylistName = "My Peapod"
View Source
const (
	ErrInvalidURL = Error("invalid url")
)

General errors.

Variables

This section is empty.

Functions

func GenerateToken

func GenerateToken() string

GenerateToken returns a random string.

func IsLocal

func IsLocal(hostname string) bool

IsLocal returns true if the host represents the local machine. This function assumes the hostname has no port.

func IsValidFilename

func IsValidFilename(name string) bool

IsValidFilename returns true if the name is in a valid format.

func IsValidJobStatus

func IsValidJobStatus(v string) bool

IsValidJobType returns true if v is a valid type.

func IsValidJobType

func IsValidJobType(v string) bool

IsValidJobType returns true if v is a valid type.

func NewContext

func NewContext(ctx context.Context, user *User) context.Context

NewContext returns a new Context that carries the authenticated user.

Types

type Error

type Error string

Error represents a peapod error.

func (Error) Error

func (e Error) Error() string

Error returns the error as a string.

type File

type File struct {
	Name string `json:"name"`
	Size int64  `json:"size"`
}

File represents an on-disk file.

type FileService

type FileService interface {
	GenerateName(ext string) string
	FindFileByName(ctx context.Context, name string) (*File, io.ReadCloser, error)
	CreateFile(ctx context.Context, f *File, r io.Reader) error
}

FileService represents a service for managing file objects.

type Job

type Job struct {
	ID         int       `json:"id"`
	OwnerID    int       `json:"owner_id"`
	Owner      *User     `json:"owner,omitempty"`
	Type       string    `json:"type"`
	Status     string    `json:"status"`
	PlaylistID int       `json:"playlist_id,omitempty"`
	Title      string    `json:"title"`
	URL        string    `json:"url,omitempty"`
	Text       string    `json:"text,omitempty"`
	Error      string    `json:"error,omitempty"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

Job represents an task to be performed by a worker.

type JobExecutor

type JobExecutor struct {
	FileService  FileService
	SMSService   SMSService
	TrackService TrackService
	TTSService   TTSService

	URLTrackGenerator URLTrackGenerator
}

JobExecutor represents a worker that executes a job.

func (*JobExecutor) ExecuteJob

func (e *JobExecutor) ExecuteJob(ctx context.Context, job *Job) error

ExecuteJob processes a single job.

type JobScheduler

type JobScheduler struct {
	FileService       FileService
	JobService        JobService
	SMSService        SMSService
	TrackService      TrackService
	TTSService        TTSService
	UserService       UserService
	URLTrackGenerator URLTrackGenerator

	LogOutput io.Writer
	// contains filtered or unexported fields
}

JobScheduler receives new jobs and schedules them for execution.

func NewJobScheduler

func NewJobScheduler() *JobScheduler

NewJobScheduler returns a new instance of JobScheduler.

func (*JobScheduler) Close

func (s *JobScheduler) Close() error

Close stops the job processing queue and waits for outstanding workers.

func (*JobScheduler) Open

func (s *JobScheduler) Open() error

Open initializes the job processing queue.

type JobService

type JobService interface {
	// Notification channel when a new job is ready.
	C() <-chan struct{}

	CreateJob(ctx context.Context, job *Job) error
	NextJob(ctx context.Context) (*Job, error)
	CompleteJob(ctx context.Context, id int, err error) error
}

JobService manages jobs in a job queue.

type Playlist

type Playlist struct {
	ID        int       `json:"id"`
	OwnerID   int       `json:"owner_id"`
	Token     string    `json:"token"`
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	Tracks []*Track `json:"tracks,omitempty"`
}

Playlist represents a time-ordered list of tracks.

func (*Playlist) LastTrackUpdatedAt

func (p *Playlist) LastTrackUpdatedAt() time.Time

LastTrackUpdatedAt returns maximum track time.

type PlaylistService

type PlaylistService interface {
	FindPlaylistByID(ctx context.Context, id int) (*Playlist, error)
	FindPlaylistByToken(ctx context.Context, token string) (*Playlist, error)
	FindPlaylistsByUserID(ctx context.Context, id int) ([]*Playlist, error)
}

PlaylistService represents a service for managing playlists.

type SMS

type SMS struct {
	ID   string
	To   string
	Body string
}

SMS represents a text message.

type SMSService

type SMSService interface {
	SendSMS(ctx context.Context, msg *SMS) error
}

SMSService sends a text message to a recipient.

type TTSService

type TTSService interface {
	SynthesizeSpeech(ctx context.Context, text string) (io.ReadCloser, error)
}

type Track

type Track struct {
	ID          int           `json:"id"`
	PlaylistID  int           `json:"playlist_id"`
	Filename    string        `json:"filename"`
	Title       string        `json:"title"`
	Description string        `json:"description"`
	Duration    time.Duration `json:"duration"`
	ContentType string        `json:"content_type"`
	Size        int           `json:"size"`
	CreatedAt   time.Time     `json:"created_at"`
	UpdatedAt   time.Time     `json:"updated_at"`
}

Track represents an audio track.

type TrackService

type TrackService interface {
	FindTrackByID(ctx context.Context, id int) (*Track, error)
	CreateTrack(ctx context.Context, track *Track) error
}

TrackService represents a service for managing audio tracks.

type URLTrackGenerator

type URLTrackGenerator interface {
	GenerateTrackFromURL(ctx context.Context, url url.URL) (*Track, io.ReadCloser, error)
}

URLTrackGenerator returns a track and file contents from a URL.

type User

type User struct {
	ID           int       `json:"id"`
	MobileNumber string    `json:"mobile_number,omitempty"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

User represents a user in the system.

func FromContext

func FromContext(ctx context.Context) *User

FromContext returns the user stored in ctx, if any.

type UserService

type UserService interface {
	FindUserByID(ctx context.Context, id int) (*User, error)
	FindUserByMobileNumber(ctx context.Context, mobileNumber string) (*User, error)
	CreateUser(ctx context.Context, user *User) error
}

UserService represents a service for managing users.

Directories

Path Synopsis
Package bolt is a generated protocol buffer package.
Package bolt is a generated protocol buffer package.
cmd

Jump to

Keyboard shortcuts

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