app

package
v0.0.0-...-ad8ca4c Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchEntity = errors.New("Not such entity in database")
)

Functions

This section is empty.

Types

type App

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

func New

func New(db DB, user UserService, handler HttpHandler) App

func (*App) HandleFuncAuthed

func (app *App) HandleFuncAuthed(path string, handle func(http.ResponseWriter,
	*http.Request))

func (*App) Run

func (app *App) Run(port string) error

type DB

type DB interface {
	GetUser(context.Context, uuid.UUID) (User, error)
	GetUsers(context.Context) ([]User, error)
	PutUser(context.Context, User) error
	CreateSubscription(context.Context, Subscription) error
	ReadSubscription(context.Context, uuid.UUID) (Subscription, error)
	ReadAllSubscriptions(context.Context) ([]Subscription, error)
	GetKey(context.Context) (KeyPair, error)
	PutKey(context.Context, KeyPair) error
	ReadPosts(context.Context) ([]Post, error)
	PutPost(context.Context, Post) error
}

type HttpHandler

type HttpHandler interface {
	HandleFunc(string, func(http.ResponseWriter, *http.Request))
	ListenAndServe(string, http.Handler) error
}

type KeyPair

type KeyPair struct {
	PK string
	SK string
}

type Post

type Post struct {
	ID   uuid.UUID `json:"id" datastore:"-"`
	User User      `json:"user"`
	Text string    `json:"text"`
	Time Time      `json:"time"`
}

type Subscription

type Subscription struct {
	UserID   uuid.UUID `json:"-" datastore:"-"`
	Endpoint string    `json:"endpoint"`
	P256dh   string    `json:"p256dh"`
	Auth     string    `json:"auth"`
}

type Time

type Time struct {
	time.Time
}

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (*Time) Scanner

func (t *Time) Scanner(src interface{}) error

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) error

func (Time) Value

func (t Time) Value() (driver.Value, error)

type User

type User struct {
	ID   uuid.UUID `json:"id" datastore:"-"`
	Name string    `json:"name"`
}

type UserService

type UserService interface {
	Current(context.Context) uuid.UUID
	Decorate(*http.Request) (context.Context, error)
	Register(context.Context, string) (User, error)
	Login(context.Context, string) (uuid.UUID, error)
	GetUserByName(context.Context, string) (User, error)
}

Jump to

Keyboard shortcuts

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