Documentation ¶
Overview ¶
Package model contains the models used by exlibris. Each model lives in its own file and should be initialized in main.go so that migrations run.
Index ¶
- type APObject
- type Author
- type Book
- type BookAuthor
- type BookSubject
- type ContextKey
- type Federater
- type OutboxEntry
- type Read
- type Review
- type Subject
- type User
- func (u *User) GenerateJWT() (string, error)
- func (u *User) GenerateKeys() error
- func (u *User) IRI() *url.URL
- func (u *User) InboxIRI() *url.URL
- func (u *User) IsPassword(password string) bool
- func (u *User) OutboxIRI() *url.URL
- func (u *User) SetPassword(password string)
- func (u *User) ToType() vocab.Type
- func (u *User) ValidateJWT(t string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APObject ¶
type APObject struct { CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` ID string `gorm:"primary key"` UserID string `gorm:"not null"` ReadID uint `gorm:"not null"` }
An APObject is an ActivityPub object (Read, Like, etc).
type Author ¶
type Author struct { Created time.Time Updated time.Time Deleted time.Time ID string `gorm:"primary_key" json:"id"` Name string `json:"name"` }
An Author is someone who has written a Book.
type Book ¶
type Book struct { ID string `gorm:"primary_key" json:"id"` Title string `gorm:"not null;index" json:"title"` Published int `json:"published,omitempty"` ISBN string `json:"isbn,omitempty"` Authors []Author `gorm:"-"` // contains filtered or unexported fields }
A Book is something that can be read. Currently this only supports things which are in the Library of Congress API, but eventually it'd be great to support fanfiction and other online-only sources.
type BookAuthor ¶
BookAuthor is a many to many model describing the authors for books
type BookSubject ¶
BookSubject for a book
type ContextKey ¶
type ContextKey string
A ContextKey is a key used to represent a model in a context
const ( // ContextKeyRequestedUser is the key to use for the username of the endpoint being requested. ContextKeyRequestedUser ContextKey = "username" // ContextKeyAuthenticatedUser is the key to use for a User object that was retrieved from a JWT. It should not be set until the JWT has been verified as being signed by the user specified in the `kid` field. ContextKeyAuthenticatedUser ContextKey = "authuser" // ContextKeyJWT is the key to use for a User's JWT in a context ContextKeyJWT ContextKey = "jwt" )
const ( // ContextKeyRead is the context key to use for the read action ContextKeyRead ContextKey = "read" )
type OutboxEntry ¶
type OutboxEntry struct { CreatedAt time.Time UserID string `gorm:"primary_key"` Serialized string `gorm:"primary_key"` }
An OutboxEntry represents an entry in a user's AP outbox.
type Read ¶
type Read struct { gormuuid.UUID Created time.Time Updated time.Time Deleted time.Time BookID string `gorm:"not null"` Book *Book `gorm:"-"` UserID string `gorm:"not null"` User *User `gorm:"-"` }
Read is a many to many model describing a user who read a book. Because GORM does weird things with foreign keys we need to do it manually, unfortunately.
type User ¶
type User struct { CreatedAt time.Time UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` ID string `gorm:"primary_key"` Username string `gorm:"unique;not null;index"` DisplayName string `gorm:"not null"` Email string `gorm:"not null"` Password []byte `json:"-"` PrivateKey []byte `json:"-"` Summary string CryptoPrivateKey crypto.PrivateKey `gorm:"-"` Local bool `json:"-"` }
A User is a person interacting with the app. They may not be registered on this server.
func (*User) GenerateJWT ¶
GenerateJWT generates a JWT for the user.
func (*User) GenerateKeys ¶
GenerateKeys is used on user registration to generate a private key for a user. It can theoretically be used to invalidate all existing tokens/sessions.
func (*User) IsPassword ¶
IsPassword verifies that the specified password matches what's in the database.
func (*User) SetPassword ¶
SetPassword is used to hash the password the user wishes to use.
func (*User) ValidateJWT ¶
ValidateJWT accepts a JWT and private key and verifies the token was signed by the key.