avatar

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SizeMini   = AvatarSize{SVGSize: 32, ASCIIWidth: 10, ASCIIHeight: 5}
	SizeSmall  = AvatarSize{SVGSize: 64, ASCIIWidth: 20, ASCIIHeight: 10}
	SizeMedium = AvatarSize{SVGSize: 128, ASCIIWidth: 40, ASCIIHeight: 20}
	SizeLarge  = AvatarSize{SVGSize: 256, ASCIIWidth: 60, ASCIIHeight: 30}
)

Predefined avatar sizes

Functions

func ConvertSVGToASCII

func ConvertSVGToASCII(svgURL string, size AvatarSize) (string, error)

ConvertSVGToASCII converts SVG from URL to ASCII art using ascii-image-converter

Types

type Avatar

type Avatar struct {
	Username    string
	Level       int
	Style       string
	Size        AvatarSize
	SVGData     []byte
	ASCIIArt    string
	Seed        string
	GeneratedAt time.Time
	CacheKey    string
}

Avatar represents a generated avatar with metadata

type AvatarCache

type AvatarCache struct {
	// contains filtered or unexported fields
}

AvatarCache handles local caching of avatars

func NewAvatarCache

func NewAvatarCache(cacheDir string, ttl time.Duration) (*AvatarCache, error)

NewAvatarCache creates a new avatar cache

func (*AvatarCache) CleanupBySize

func (c *AvatarCache) CleanupBySize(maxSize int64) error

CleanupBySize removes least recently used entries until size is under limit

func (*AvatarCache) Clear

func (c *AvatarCache) Clear() error

Clear removes all cached avatars

func (*AvatarCache) Delete

func (c *AvatarCache) Delete(cacheKey string) error

Delete removes an avatar from cache

func (*AvatarCache) Get

func (c *AvatarCache) Get(cacheKey string) (*Avatar, error)

Get retrieves an avatar from cache

func (*AvatarCache) GetCacheSize

func (c *AvatarCache) GetCacheSize() (int64, error)

GetCacheSize returns the total size of the cache in bytes

func (*AvatarCache) GetStats

func (c *AvatarCache) GetStats() (CacheStats, error)

GetStats returns cache statistics

func (*AvatarCache) Set

func (c *AvatarCache) Set(cacheKey string, avatar *Avatar) error

Set stores an avatar in cache

type AvatarManager

type AvatarManager struct {
	// contains filtered or unexported fields
}

AvatarManager handles avatar generation, caching, and management

func NewAvatarManager

func NewAvatarManager(config *Config) (*AvatarManager, error)

NewAvatarManager creates a new avatar manager with the given configuration

func (*AvatarManager) Generate

func (am *AvatarManager) Generate(request AvatarRequest) (*Avatar, error)

Generate creates or retrieves an avatar for the given request

func (*AvatarManager) GetCached

func (am *AvatarManager) GetCached(cacheKey string) (*Avatar, error)

GetCached retrieves an avatar from cache if it exists

func (*AvatarManager) Refresh

func (am *AvatarManager) Refresh(username string) error

Refresh forces regeneration of an avatar, bypassing cache

type AvatarRequest

type AvatarRequest struct {
	Username string
	Level    int
	Style    string
	Size     AvatarSize
}

AvatarRequest represents a request for avatar generation

type AvatarSize

type AvatarSize struct {
	SVGSize     int // 64, 128, 256
	ASCIIWidth  int // 20, 40, 60
	ASCIIHeight int // 10, 20, 30
}

AvatarSize defines the dimensions for avatar generation

type CacheEntry

type CacheEntry struct {
	Avatar      *Avatar   `json:"avatar"`
	CachedAt    time.Time `json:"cached_at"`
	ExpiresAt   time.Time `json:"expires_at"`
	AccessCount int       `json:"access_count"`
	LastAccess  time.Time `json:"last_access"`
}

CacheEntry represents a cached avatar with metadata

type CacheStats

type CacheStats struct {
	TotalEntries     int     `json:"total_entries"`
	ValidEntries     int     `json:"valid_entries"`
	ExpiredEntries   int     `json:"expired_entries"`
	TotalSize        int64   `json:"total_size"`
	TotalAccessCount int     `json:"total_access_count"`
	HitRate          float64 `json:"hit_rate"`
}

CacheStats represents cache statistics

type Config

type Config struct {
	CacheDir     string
	CacheTTL     time.Duration
	APITimeout   time.Duration
	DefaultStyle string
	DefaultSize  AvatarSize
}

Config holds avatar system configuration

func GetDefaultConfig

func GetDefaultConfig() *Config

GetDefaultConfig returns a default configuration

type DiceBearClient

type DiceBearClient struct {
	// contains filtered or unexported fields
}

DiceBearClient handles communication with DiceBear API

func NewDiceBearClient

func NewDiceBearClient(timeout time.Duration) *DiceBearClient

NewDiceBearClient creates a new DiceBear API client

func (*DiceBearClient) GenerateAvatar

func (c *DiceBearClient) GenerateAvatar(style string, params DiceBearParams) ([]byte, error)

GenerateAvatar fetches an SVG avatar from DiceBear API

func (*DiceBearClient) GenerateAvatarURL

func (c *DiceBearClient) GenerateAvatarURL(style string, params DiceBearParams) string

GenerateAvatarURL returns the DiceBear API URL for the given style and parameters

func (*DiceBearClient) GetStyleInfo

func (c *DiceBearClient) GetStyleInfo(style string) StyleInfo

GetStyleInfo returns information about a specific style

func (*DiceBearClient) GetSupportedStyles

func (c *DiceBearClient) GetSupportedStyles() []string

GetSupportedStyles returns a list of supported avatar styles

func (*DiceBearClient) TestConnection

func (c *DiceBearClient) TestConnection() error

TestConnection tests the connection to DiceBear API

func (*DiceBearClient) ValidateStyle

func (c *DiceBearClient) ValidateStyle(style string) bool

ValidateStyle checks if a style is supported

type DiceBearParams

type DiceBearParams struct {
	Seed               string
	Size               int
	BackgroundType     []string
	BackgroundRotation []int
	Accessories        []string
	AccessoriesColor   []string
	HairColor          []string
	Flip               bool
	Rotate             int
	Scale              int
	Radius             int
	TranslateX         int
	TranslateY         int
}

DiceBearParams represents parameters for DiceBear API

type StyleInfo

type StyleInfo struct {
	Name        string
	Description string
	Recommended bool
	Features    []string
}

StyleInfo contains information about an avatar style

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL