Documentation ¶
Index ¶
Constants ¶
View Source
const ( DefaultAvatarHeight = 160 DefaultAvatarWidth = 0 // we'll go for the height so width should be set by aspect ration )
Variables ¶
View Source
var AvatarDirective = service.Directive{ Name: "avatars", Init: func(s *service.Instance, d config.Dispenser) error { if !d.Next() { return d.SyntaxErr("") } a := &avatarDatabase{} var ( width int height int err error ) for d.NextBlock() { switch d.Val() { case "path": if !d.NextArg() { return d.ArgErr() } a.rootPath = d.Val() case "width": if !d.NextArg() { return d.ArgErr() } width, err = strconv.Atoi(d.Val()) if err != nil { return d.SyntaxErr(err.Error()) } case "height": if !d.NextArg() { return d.ArgErr() } height, err = strconv.Atoi(d.Val()) if err != nil { return d.SyntaxErr(err.Error()) } } } if a.rootPath == "" { return d.SyntaxErr("avatars: missing path") } if width == 0 && height == 0 { a.width = DefaultAvatarWidth a.height = DefaultAvatarHeight } else { a.width = uint(width) a.height = uint(height) } a.rootPath = filepath.Clean(a.rootPath) stat, err := os.Stat(a.rootPath) if err != nil { return err } if !stat.IsDir() { return errors.New("avatars path must be a directory") } s.AddProvider(AvatarKey, a) return nil }, }
AvatarDirective is used to configure the avatar storage path
View Source
var AvatarKey = avatarCtxKey{}
AvatarKey is used to associate an AvatarDatabase with an api.Router
Functions ¶
This section is empty.
Types ¶
type AvatarDatabase ¶
type AvatarDatabase interface { // Get loads the avatar with the given account ID from the database Get(accountID int) (io.ReadCloser, int64, error) // Save saves the avatar for the given account ID // Avatar images are always saved in image/png format Save(accountID int, data io.ReadCloser) error }
AvatarDatabase manages user avatars
func GetAvatarDB ¶
func GetAvatarDB(r api.Router) AvatarDatabase
GetAvatarDB returns the avatar database associated with r
type Database ¶
type Database interface { // CreateUser creates a new user CreateUser(context.Context, iam.User) error // GetUserByID returns the iam.User with the given account ID GetUserByID(context.Context, string) (*iam.User, error) // GetUserByName returns the iam.User with the given username GetUserByName(context.Context, string) (*iam.User, error) // GetUserGroups returns a list of groups the user belongs to GetUserGroups(context.Context, string) ([]*iam.Group, error) // DeleteUser deletes a user from the database. The calles // is responsible for archiving the user on the authn server DeleteUser(context.Context, string) error // UpdateUser updates an existing user UpdateUser(context.Context, iam.User) (*iam.User, error) // ListUsers returns all users stored in the database ListUsers(context.Context) ([]*iam.User, error) }
Database wraps any database access and is provided as a router dependecy provider
func GetDatabase ¶
GetDatabase returns the user Database associated with r
Click to show internal directories.
Click to hide internal directories.