Documentation ¶
Index ¶
- func CheckCredentials(username, password string, s Storer) error
- type FedEmbeddedStorage
- func (fs *FedEmbeddedStorage) Begin() (Tx, error)
- func (fs *FedEmbeddedStorage) Close() error
- func (fs *FedEmbeddedStorage) DeleteObject(iri *url.URL) error
- func (fs *FedEmbeddedStorage) Open() (err error)
- func (fs *FedEmbeddedStorage) RetrieveCode(code string) (*FedOAuthCode, error)
- func (fs *FedEmbeddedStorage) RetrieveObject(iri *url.URL) (obj vocab.Type, err error)
- func (fs *FedEmbeddedStorage) RetrieveToken(token string) (*FedOAuthToken, error)
- func (fs *FedEmbeddedStorage) RetrieveUser(username string) (user *FedUser, err error)
- func (fs *FedEmbeddedStorage) StoreCode(code *FedOAuthCode) error
- func (fs *FedEmbeddedStorage) StoreObject(iri *url.URL, obj vocab.Type) error
- func (fs *FedEmbeddedStorage) StoreToken(token *FedOAuthToken) error
- func (fs *FedEmbeddedStorage) StoreUser(user *FedUser) error
- type FedEmptyStorage
- func (f FedEmptyStorage) Begin() (Tx, error)
- func (f FedEmptyStorage) Close() error
- func (f FedEmptyStorage) Commit() error
- func (f FedEmptyStorage) DeleteObject(iri *url.URL) error
- func (f FedEmptyStorage) Open() error
- func (f FedEmptyStorage) RetrieveCode(code string) (*FedOAuthCode, error)
- func (f FedEmptyStorage) RetrieveObject(iri *url.URL) (vocab.Type, error)
- func (f FedEmptyStorage) RetrieveToken(token string) (*FedOAuthToken, error)
- func (f FedEmptyStorage) RetrieveUser(username string) (*FedUser, error)
- func (f FedEmptyStorage) Rollback() error
- func (f FedEmptyStorage) StoreCode(code *FedOAuthCode) error
- func (f FedEmptyStorage) StoreObject(iri *url.URL, obj vocab.Type) error
- func (f FedEmptyStorage) StoreToken(token *FedOAuthToken) error
- func (f FedEmptyStorage) StoreUser(user *FedUser) error
- type FedOAuthCode
- type FedOAuthToken
- type FedStorage
- type FedUser
- func (u *FedUser) Collections() [][]*url.URL
- func (u *FedUser) HasLiked(id *url.URL) bool
- func (u *FedUser) IsFollowedBy(id *url.URL) bool
- func (u *FedUser) IsFollowing(id *url.URL) bool
- func (u *FedUser) PasswordOK(password string) bool
- func (u *FedUser) SetPassword(password string)
- func (u *FedUser) String() string
- type Storer
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckCredentials ¶
Check credentials in storage s. If they are valid credentials, this function returns nil. Otherwise it returns an error telling you what's wrong with the credentials.
Types ¶
type FedEmbeddedStorage ¶
type FedEmbeddedStorage struct { Filepath string // contains filtered or unexported fields }
func (*FedEmbeddedStorage) Begin ¶
func (fs *FedEmbeddedStorage) Begin() (Tx, error)
func (*FedEmbeddedStorage) Close ¶
func (fs *FedEmbeddedStorage) Close() error
func (*FedEmbeddedStorage) DeleteObject ¶
func (fs *FedEmbeddedStorage) DeleteObject(iri *url.URL) error
func (*FedEmbeddedStorage) Open ¶
func (fs *FedEmbeddedStorage) Open() (err error)
func (*FedEmbeddedStorage) RetrieveCode ¶
func (fs *FedEmbeddedStorage) RetrieveCode(code string) (*FedOAuthCode, error)
func (*FedEmbeddedStorage) RetrieveObject ¶
func (*FedEmbeddedStorage) RetrieveToken ¶
func (fs *FedEmbeddedStorage) RetrieveToken(token string) (*FedOAuthToken, error)
func (*FedEmbeddedStorage) RetrieveUser ¶
func (fs *FedEmbeddedStorage) RetrieveUser(username string) (user *FedUser, err error)
func (*FedEmbeddedStorage) StoreCode ¶
func (fs *FedEmbeddedStorage) StoreCode(code *FedOAuthCode) error
func (*FedEmbeddedStorage) StoreObject ¶
func (*FedEmbeddedStorage) StoreToken ¶
func (fs *FedEmbeddedStorage) StoreToken(token *FedOAuthToken) error
func (*FedEmbeddedStorage) StoreUser ¶
func (fs *FedEmbeddedStorage) StoreUser(user *FedUser) error
type FedEmptyStorage ¶
type FedEmptyStorage struct{}
Implements FedStorage, Storer and Tx, but never returns any errors or actual content.
Can be used in tests where we do not want to retrieve anything from storage.
func (FedEmptyStorage) Begin ¶
func (f FedEmptyStorage) Begin() (Tx, error)
func (FedEmptyStorage) Close ¶
func (f FedEmptyStorage) Close() error
func (FedEmptyStorage) Commit ¶
func (f FedEmptyStorage) Commit() error
func (FedEmptyStorage) DeleteObject ¶
func (f FedEmptyStorage) DeleteObject(iri *url.URL) error
func (FedEmptyStorage) Open ¶
func (f FedEmptyStorage) Open() error
func (FedEmptyStorage) RetrieveCode ¶
func (f FedEmptyStorage) RetrieveCode(code string) (*FedOAuthCode, error)
func (FedEmptyStorage) RetrieveObject ¶
func (FedEmptyStorage) RetrieveToken ¶
func (f FedEmptyStorage) RetrieveToken(token string) (*FedOAuthToken, error)
func (FedEmptyStorage) RetrieveUser ¶
func (f FedEmptyStorage) RetrieveUser(username string) (*FedUser, error)
func (FedEmptyStorage) Rollback ¶
func (f FedEmptyStorage) Rollback() error
func (FedEmptyStorage) StoreCode ¶
func (f FedEmptyStorage) StoreCode(code *FedOAuthCode) error
func (FedEmptyStorage) StoreObject ¶
func (FedEmptyStorage) StoreToken ¶
func (f FedEmptyStorage) StoreToken(token *FedOAuthToken) error
func (FedEmptyStorage) StoreUser ¶
func (f FedEmptyStorage) StoreUser(user *FedUser) error
type FedOAuthCode ¶
func NewFedOAuthCode ¶
func NewFedOAuthCode(username, password string, target Storer) (*FedOAuthCode, error)
If username/password are valid credentials, create a new code, store it into target and return it.
func (*FedOAuthCode) Expired ¶
func (c *FedOAuthCode) Expired() bool
Return whether this code is expired.
func (*FedOAuthCode) UnmarshalJSON ¶
func (c *FedOAuthCode) UnmarshalJSON(data []byte) error
Unmarshal override to avoid confusion with FedOAuthToken.
type FedOAuthToken ¶
func NewFedOAuthToken ¶
func NewFedOAuthToken(username, password string, target Storer) (*FedOAuthToken, error)
If username/password are valid credentials, create a new token, store it into target and return it.
func NewFedOAuthTokenFor ¶
func NewFedOAuthTokenFor(username string, target Storer) (*FedOAuthToken, error)
Create a new token for username, store it into target and return it.
func (*FedOAuthToken) Expired ¶
func (c *FedOAuthToken) Expired() bool
Return whether this token is expired.
func (*FedOAuthToken) UnmarshalJSON ¶
func (c *FedOAuthToken) UnmarshalJSON(data []byte) error
Unmarshal override to avoid confusion with FedOAuthCode.
type FedStorage ¶
type FedStorage interface { // Open the underlying connection to the database. Before using // any of the other methods of a FedStorage, call Open first. Open() error // Close the connection to the underlying database. Close() error // Start a new transaction. Remember to call Rollback or Commit! Begin() (Tx, error) // FedStorage implements Storer. Calling its methods creates // a single-operation transaction and automatically commits. Storer }
Represents a connection to some database that takes care of storing all fed related data that isn't configuration, that is user meta data, active session tokens and the actual activities and objects.
FedStorage provides the Begin method which returns a transaction. A transaction combines any number of operations (as defined by Storer) and allows us to apply them atomically.
If you just want to run a single operation, you can also call the Storer methods directly.
type FedUser ¶
type FedUser struct { Name string PasswordSHA256 []byte Inbox []*url.URL Outbox []*url.URL Following []*url.URL Followers []*url.URL Liked []*url.URL }
Represents a user registered with the service.
func (*FedUser) Collections ¶
Return a slice that contains all collections (i.e. Inbox, Outbox, Following, Followers and Liked).
func (*FedUser) IsFollowedBy ¶
Returns whether id is following this user.
func (*FedUser) IsFollowing ¶
Returns whether this user is following whatever is at id.
func (*FedUser) PasswordOK ¶
Return whether plaintext password, when hashed, matches the assigned password.
func (*FedUser) SetPassword ¶
Hash the plaintext password and assign the result to FedUser.PasswordSHA256.
type Storer ¶
type Storer interface { // Retrieve the metadata for a user with the given username. // If no such user exists, an error is returned. RetrieveUser(username string) (*FedUser, error) // Write metadata for user. If a user with matching user.Name // already exists, it is overwritten. StoreUser(user *FedUser) error // Retreive metadta for given code. If no such code is recorded // or if it is expired, an error is returned. RetrieveCode(code string) (*FedOAuthCode, error) // Write metadata for code. If a code with matching code.Code // already exists, it is overwritten. StoreCode(code *FedOAuthCode) error // Retreive metadta for given token. If no such token is recorded // or if it is expired, an error is returned. RetrieveToken(token string) (*FedOAuthToken, error) // Write metadata for token. If a token with matching token.Token // already exists, it is overwritten. StoreToken(token *FedOAuthToken) error // Retrieve the object at iri. RetrieveObject(iri *url.URL) (vocab.Type, error) // Write the object at iri. If there already is an object // stored at the given iri, it is overwritten. StoreObject(iri *url.URL, obj vocab.Type) error // Delete the object at iri. DeleteObject(iri *url.URL) error }
Defines operations on a database required by fed.
type Tx ¶
type Tx interface { // Commit all changes made within this transaction. You can // call this method as often as you want, only the first call // to Commit or Rollback for a given instance will be applied. Commit() error // Undo all changes made by this transaction. You can call // this method as often as you want, only the first call to Commit // or Rollback for a given instance will be applied. Rollback() error // Tx implements Storer. Calling its methods is only applied // after a successful call to Commit. If you wish to undo // the changes, call Rollback instead. Storer }
A single transaction. Create one if you do operations on the database you may want to revert. You absolutly musn't forget to call either Commit or Rollback, otherwise fed will deadlock.