Documentation
¶
Overview ¶
Package qrcode provides QR code generation for GoSPA applications. It integrates with the auth plugin for TOTP/OTP setup and can be used independently for any QR code generation needs.
Index ¶
- func ForOTP(otpURL string, opts ...Option) (string, error)
- func Generate(content string, opts ...Option) (image.Image, error)
- func GenerateBase64(content string, opts ...Option) (string, error)
- func GenerateDataURL(content string, opts ...Option) (string, error)
- func GeneratePNG(content string, opts ...Option) ([]byte, error)
- func GeneratePNGWithLogo(content string, logo image.Image, opts ...Option) ([]byte, error)
- func GenerateWithLogo(content string, logo image.Image, opts ...Option) (image.Image, error)
- type Config
- type Level
- type Option
- type Plugin
- func (p *Plugin) Dependencies() []plugin.Dependency
- func (p *Plugin) ForOTP(otpURL string, opts ...Option) (string, error)
- func (p *Plugin) Generate(content string, opts ...Option) (image.Image, error)
- func (p *Plugin) GenerateDataURL(content string, opts ...Option) (string, error)
- func (p *Plugin) GeneratePNG(content string, opts ...Option) ([]byte, error)
- func (p *Plugin) GeneratePNGWithLogo(content string, logo image.Image, opts ...Option) ([]byte, error)
- func (p *Plugin) GenerateWithLogo(content string, logo image.Image, opts ...Option) (image.Image, error)
- func (p *Plugin) Init() error
- func (p *Plugin) Name() string
- func (p *Plugin) NewQRCode(content string, opts ...Option) *QRCode
- type QRCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateBase64 ¶
GenerateBase64 generates a base64-encoded PNG QR code.
func GenerateDataURL ¶
GenerateDataURL generates a data URL for the QR code.
func GeneratePNG ¶
GeneratePNG generates a PNG-encoded QR code.
func GeneratePNGWithLogo ¶
GeneratePNGWithLogo generates a PNG QR code with a logo.
Types ¶
type Config ¶
type Config struct {
// Default size in pixels (default: 256).
DefaultSize int `yaml:"default_size" json:"defaultSize"`
// Error correction level: low, medium, quartile, high (default: medium).
DefaultLevel string `yaml:"default_level" json:"defaultLevel"`
}
Config holds plugin configuration from gospa.yaml.
type Option ¶
type Option func(*QRCode)
Option is a functional option for QR code generation.
func WithColors ¶
WithColors sets the foreground and background colors.
type Plugin ¶ added in v0.1.23
type Plugin struct {
// DefaultSize is the default QR code size in pixels.
DefaultSize int
// DefaultLevel is the default error correction level.
DefaultLevel Level
// DefaultForeground is the default foreground color.
DefaultForeground color.Color
// DefaultBackground is the default background color.
DefaultBackground color.Color
}
Plugin is the QR code generation plugin for GoSPA.
func NewPlugin ¶
func NewPlugin() *Plugin
NewPlugin creates a new QR code plugin with default settings.
func NewWithConfig ¶
NewWithConfig creates a new QR code plugin with configuration.
func (*Plugin) Dependencies ¶ added in v0.1.23
func (p *Plugin) Dependencies() []plugin.Dependency
Dependencies returns the plugin dependencies.
func (*Plugin) ForOTP ¶ added in v0.1.23
ForOTP generates a QR code for OTP/TOTP setup. The URL should be in the format: otpauth://totp/Issuer:Account?secret=XXX&issuer=Issuer
func (*Plugin) Generate ¶ added in v0.1.23
Generate generates a QR code image for the given content.
func (*Plugin) GenerateDataURL ¶ added in v0.1.23
GenerateDataURL generates a data URL for the QR code.
func (*Plugin) GeneratePNG ¶ added in v0.1.23
GeneratePNG generates a PNG-encoded QR code.
func (*Plugin) GeneratePNGWithLogo ¶ added in v0.1.23
func (p *Plugin) GeneratePNGWithLogo(content string, logo image.Image, opts ...Option) ([]byte, error)
GeneratePNGWithLogo generates a PNG QR code with a logo.
type QRCode ¶
type QRCode struct {
Content string
Level Level
Size int
// Module colors
Foreground color.Color
Background color.Color
}
QRCode represents a QR code.
func NewQRCode ¶
NewQRCode creates a new QR code with the given content and options. Uses the default plugin settings.