Documentation
¶
Index ¶
- Constants
- Variables
- func IsValidFormat(format Format) bool
- func IsValidStyle(style Style) bool
- func RandomString(length int) string
- type Avatar
- func (a *Avatar) CustomParams() map[string]string
- func (a *Avatar) Customize(params map[string]string, replace bool) error
- func (a *Avatar) Edit(style Style, seed string, options *Options) error
- func (a *Avatar) GetBytes(format Format) ([]byte, error)
- func (a *Avatar) GetSchema() (map[string]interface{}, error)
- func (a *Avatar) GetText(format Format) (string, error)
- func (a *Avatar) Options() *Options
- func (a *Avatar) Save(format Format, outputFilepath string, overwrite bool) (string, error)
- func (a *Avatar) Seed() string
- func (a *Avatar) Style() Style
- func (a *Avatar) URL() string
- func (a *Avatar) URLWithFormat(format Format) (string, error)
- func (a *Avatar) View(format Format) error
- type Color
- type Format
- type HTTPResponseError
- type ImageFormatError
- type InvalidColorError
- type InvalidStyleError
- type Options
- type Style
Constants ¶
View Source
const ( BaseURL = "https://api.dicebear.com/9.x" // Base URL for DiceBear API Timeout = 30 // Default timeout in seconds )
Variables ¶
View Source
var ( ErrInvalidOption = errors.New("invalid option") ErrNetworkRequest = errors.New("network request failed") ErrImageSave = errors.New("failed to save image") ErrFileOperationFailed = errors.New("file operation failed") )
Common errors
AllFormats is a list of all available image formats.
View Source
var AllStyles = []Style{ Adventurer, AdventurerNeutral, Avataaars, AvataaarsNeutral, BigEars, BigEarsNeutral, BigSmile, Bottts, BotttsNeutral, Croodles, CroodlesNeutral, Dylan, FunEmoji, Glass, Icons, Identicon, Initials, Lorelei, LoreleiNeutral, Micah, Miniavs, Notionists, NotionistsNeutral, OpenPeeps, Personas, PixelArt, PixelArtNeutral, Rings, Shapes, Thumbs, }
AllStyles is a list of all available avatar styles.
Functions ¶
func IsValidFormat ¶
IsValidFormat checks if a format is valid.
func RandomString ¶
RandomString generates a random string of specified length.
Types ¶
type Avatar ¶
type Avatar struct {
// contains filtered or unexported fields
}
Avatar represents a DiceBear avatar.
func NewAvatar ¶
func NewAvatar(style Style, seed string, options *Options, customParams map[string]string) (*Avatar, error)
NewAvatar creates a new Avatar with the given style and seed.
func (*Avatar) CustomParams ¶
CustomParams returns the custom parameters of the avatar.
func (*Avatar) URLWithFormat ¶
URLWithFormat returns the URL of the avatar with the specified format.
type Color ¶
type Color string
Color represents a color in hex or "transparent" format.
type HTTPResponseError ¶
func (*HTTPResponseError) Error ¶
func (e *HTTPResponseError) Error() string
type ImageFormatError ¶
type ImageFormatError struct{ Format Format }
func (*ImageFormatError) Error ¶
func (e *ImageFormatError) Error() string
type InvalidColorError ¶
type InvalidColorError struct{ Code string }
func (*InvalidColorError) Error ¶
func (e *InvalidColorError) Error() string
type InvalidStyleError ¶
type InvalidStyleError struct{ Style Style }
Error types with context
func (*InvalidStyleError) Error ¶
func (e *InvalidStyleError) Error() string
type Options ¶
type Options struct { Flip bool `json:"flip,omitempty"` Rotate int `json:"rotate,omitempty"` Scale int `json:"scale,omitempty"` Radius int `json:"radius,omitempty"` Size int `json:"size,omitempty"` BackgroundColor Color `json:"-"` BackgroundType string `json:"backgroundType,omitempty"` BackgroundRotation int `json:"backgroundRotation,omitempty"` TranslateX int `json:"translateX,omitempty"` TranslateY int `json:"translateY,omitempty"` RandomizeIDs bool `json:"randomizeIds,omitempty"` }
Options defines avatar customization options.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns the default avatar options.
type Style ¶
type Style string
Style represents the available avatar styles.
const ( Adventurer Style = "adventurer" // Friendly adventurer style AdventurerNeutral Style = "adventurer-neutral" // Neutral adventurer style Avataaars Style = "avataaars" // Avatar style inspired by avataaars AvataaarsNeutral Style = "avataaars-neutral" // Neutral avataaars style BigEars Style = "big-ears" // Big ears style BigEarsNeutral Style = "big-ears-neutral" // Neutral big ears style BigSmile Style = "big-smile" // Big smile style Bottts Style = "bottts" // Bottts style BotttsNeutral Style = "bottts-neutral" // Neutral bottts style Croodles Style = "croodles" // Croodles style CroodlesNeutral Style = "croodles-neutral" // Neutral croodles style Dylan Style = "dylan" // Dylan style FunEmoji Style = "fun-emoji" // Fun emoji style Glass Style = "glass" // Glass style Icons Style = "icons" // Icons style Identicon Style = "identicon" // Identicon style Initials Style = "initials" // Initials style Lorelei Style = "lorelei" // Lorelei style LoreleiNeutral Style = "lorelei-neutral" // Neutral lorelei style Micah Style = "micah" // Micah style Miniavs Style = "miniavs" // Miniavs style Notionists Style = "notionists" // Notionists style NotionistsNeutral Style = "notionists-neutral" // Neutral notionists style OpenPeeps Style = "open-peeps" // Open peeps style Personas Style = "personas" // Personas style PixelArt Style = "pixel-art" // Pixel art style PixelArtNeutral Style = "pixel-art-neutral" // Neutral pixel art style Rings Style = "rings" // Rings style Shapes Style = "shapes" // Shapes style Thumbs Style = "thumbs" // Thumbs style )
Click to show internal directories.
Click to hide internal directories.