service

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

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

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func WithAuthorizer

func WithAuthorizer(auth string) optionFunc

Types

type Fact

type Fact struct {
	ID        int64     `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	DeletedAt time.Time `json:"-"`
	Content   string    `json:"content"`
	Source    string    `json:"source"`
}

type FactRepo

type FactRepo interface {
	Facts(context.Context) ([]Fact, error)
	Fact(ctx context.Context, id int64) (Fact, error)
	RandomFact(context.Context) (Fact, error)
	CreateFact(ctx context.Context, contents, source string) (Fact, error)
	DeleteFact(ctx context.Context, id int64) error
}

type Option

type Option interface {
	Apply(s *Service)
}

type Service

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

func New

func New(f FactRepo, opts ...Option) *Service

func (*Service) FactHandler

func (s *Service) FactHandler(w http.ResponseWriter, r *http.Request)

func (*Service) FactsHandler

func (s *Service) FactsHandler(w http.ResponseWriter, r *http.Request)

func (*Service) RespondErrorJSON

func (s *Service) RespondErrorJSON(w http.ResponseWriter, code int, err error)

func (*Service) RespondJSON

func (s *Service) RespondJSON(w http.ResponseWriter, code int, envelope map[string]any)

func (*Service) Routes

func (s *Service) Routes() *httprouter.Router

Jump to

Keyboard shortcuts

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