Documentation ¶
Overview ¶
Package avatar implements avatart proxy for oauth and defines store interface and implements local (fs), gridfs (mongo) and boltdb stores.
Index ¶
- func GenerateAvatar(user string) ([]byte, error)
- func GetGravatarURL(email string) (res string, err error)
- func Migrate(dst, src Store) (int, error)
- type BoltDB
- func (b *BoltDB) Close() error
- func (b *BoltDB) Get(avatarID string) (reader io.ReadCloser, size int, err error)
- func (b *BoltDB) ID(avatarID string) (id string)
- func (b *BoltDB) List() (ids []string, err error)
- func (b *BoltDB) Put(userID string, reader io.Reader) (avatar string, err error)
- func (b *BoltDB) Remove(avatarID string) (err error)
- func (b *BoltDB) String() string
- type GridFS
- func (gf *GridFS) Close() error
- func (gf *GridFS) Get(avatar string) (reader io.ReadCloser, size int, err error)
- func (gf *GridFS) ID(avatar string) (id string)
- func (gf *GridFS) List() (ids []string, err error)
- func (gf *GridFS) Put(userID string, reader io.Reader) (avatar string, err error)
- func (gf *GridFS) Remove(avatar string) error
- func (gf *GridFS) String() string
- type LocalFS
- func (fs *LocalFS) Close() error
- func (fs *LocalFS) Get(avatar string) (reader io.ReadCloser, size int, err error)
- func (fs *LocalFS) ID(avatar string) (id string)
- func (fs *LocalFS) List() (ids []string, err error)
- func (fs *LocalFS) Put(userID string, reader io.Reader) (avatar string, err error)
- func (fs *LocalFS) Remove(avatar string) error
- func (fs *LocalFS) String() string
- type NoOp
- func (s *NoOp) Close() error
- func (s *NoOp) Get(string) (reader io.ReadCloser, size int, err error)
- func (s *NoOp) ID(string) (id string)
- func (s *NoOp) List() (ids []string, err error)
- func (s *NoOp) Put(string, io.Reader) (avatarID string, err error)
- func (s *NoOp) Remove(string) error
- func (s *NoOp) String() string
- type Proxy
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateAvatar ¶
GenerateAvatar for give user with identicon
func GetGravatarURL ¶
GetGravatarURL returns url to gravatar picture for given email
Types ¶
type BoltDB ¶
type BoltDB struct {
// contains filtered or unexported fields
}
BoltDB implements avatar store with bolt using separate db (file) with "avatars" bucket to keep image bin and "metas" bucket to keep sha1 of picture. avatarID (base file name) used as a key for both.
func (*BoltDB) Put ¶
Put avatar to bolt, key by avatarID. Trying to resize image and lso calculates sha1 of the file for ID func
type GridFS ¶
type GridFS struct {
// contains filtered or unexported fields
}
GridFS implements Store for GridFS
func (*GridFS) ID ¶
ID returns a fingerprint of the avatar content. Uses MD5 because gridfs provides it directly
type LocalFS ¶
type LocalFS struct {
// contains filtered or unexported fields
}
LocalFS implements Store for local file system
func NewLocalFS ¶
NewLocalFS makes file-system avatar store
type NoOp ¶
type NoOp struct{}
NoOp is an empty (no-op) implementation of Store interface
func NewNoOp ¶
func NewNoOp() *NoOp
NewNoOp provides an empty (no-op) implementation of Store interface
type Proxy ¶
Proxy provides http handler for avatars from avatar.Store On user login token will call Put and it will retrieve and save picture locally.
type Store ¶
type Store interface { fmt.Stringer Put(userID string, reader io.Reader) (avatarID string, err error) // save avatar data from the reader and return base name Get(avatarID string) (reader io.ReadCloser, size int, err error) // load avatar via reader ID(avatarID string) (id string) // unique id of stored avatar's data Remove(avatarID string) error // remove avatar data List() (ids []string, err error) // list all avatar ids Close() error // close store }
Store defines interface to store and load avatars