qrcode

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForOTP

func ForOTP(otpURL string, opts ...Option) (string, error)

ForOTP generates a QR code for OTP/TOTP setup.

func Generate

func Generate(content string, opts ...Option) (image.Image, error)

Generate generates a QR code image for the given content.

func GenerateBase64

func GenerateBase64(content string, opts ...Option) (string, error)

GenerateBase64 generates a base64-encoded PNG QR code.

func GenerateDataURL

func GenerateDataURL(content string, opts ...Option) (string, error)

GenerateDataURL generates a data URL for the QR code.

func GeneratePNG

func GeneratePNG(content string, opts ...Option) ([]byte, error)

GeneratePNG generates a PNG-encoded QR code.

func GeneratePNGWithLogo(content string, logo image.Image, opts ...Option) ([]byte, error)

GeneratePNGWithLogo generates a PNG QR code with a logo.

func GenerateWithLogo(content string, logo image.Image, opts ...Option) (image.Image, error)

GenerateWithLogo generates a QR code with a logo in the center.

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 Level

type Level int

Level represents the error correction level.

const (
	// LevelLow 7% error recovery.
	LevelLow Level = iota
	// LevelMedium 15% error recovery.
	LevelMedium
	// LevelQuartile 25% error recovery.
	LevelQuartile
	// LevelHigh 30% error recovery.
	LevelHigh
)

type Option

type Option func(*QRCode)

Option is a functional option for QR code generation.

func WithColors

func WithColors(foreground, background color.Color) Option

WithColors sets the foreground and background colors.

func WithLevel

func WithLevel(level Level) Option

WithLevel sets the error correction level.

func WithSize

func WithSize(size int) Option

WithSize sets the size in pixels.

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

func NewQRCode(content string, opts ...Option) *QRCode

NewQRCode creates a new QR code with the given content and options. Uses the default plugin settings.

func (*QRCode) Base64

func (qr *QRCode) Base64() (string, error)

Base64 generates a base64-encoded PNG QR code.

func (*QRCode) DataURL

func (qr *QRCode) DataURL() (string, error)

DataURL generates a data URL for the QR code.

func (*QRCode) Generate

func (qr *QRCode) Generate() (image.Image, error)

Generate generates a QR code image.

func (*QRCode) PNG

func (qr *QRCode) PNG() ([]byte, error)

PNG generates a PNG-encoded QR code.

type QRCodePlugin

type QRCodePlugin 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
}

QRCodePlugin is the QR code generation plugin for GoSPA.

func NewPlugin

func NewPlugin() *QRCodePlugin

NewPlugin creates a new QR code plugin with default settings.

func NewWithConfig

func NewWithConfig(cfg Config) *QRCodePlugin

NewWithConfig creates a new QR code plugin with configuration.

func (*QRCodePlugin) Dependencies

func (p *QRCodePlugin) Dependencies() []plugin.Dependency

Dependencies returns the plugin dependencies.

func (*QRCodePlugin) ForOTP

func (p *QRCodePlugin) ForOTP(otpURL string, opts ...Option) (string, error)

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 (*QRCodePlugin) Generate

func (p *QRCodePlugin) Generate(content string, opts ...Option) (image.Image, error)

Generate generates a QR code image for the given content.

func (*QRCodePlugin) GenerateDataURL

func (p *QRCodePlugin) GenerateDataURL(content string, opts ...Option) (string, error)

GenerateDataURL generates a data URL for the QR code.

func (*QRCodePlugin) GeneratePNG

func (p *QRCodePlugin) GeneratePNG(content string, opts ...Option) ([]byte, error)

GeneratePNG generates a PNG-encoded QR code.

func (p *QRCodePlugin) GeneratePNGWithLogo(content string, logo image.Image, opts ...Option) ([]byte, error)

GeneratePNGWithLogo generates a PNG QR code with a logo.

func (p *QRCodePlugin) GenerateWithLogo(content string, logo image.Image, opts ...Option) (image.Image, error)

GenerateWithLogo generates a QR code with a logo in the center.

func (*QRCodePlugin) Init

func (p *QRCodePlugin) Init() error

Init initializes the plugin.

func (*QRCodePlugin) Name

func (p *QRCodePlugin) Name() string

Name returns the plugin name.

func (*QRCodePlugin) NewQRCode

func (p *QRCodePlugin) NewQRCode(content string, opts ...Option) *QRCode

NewQRCode creates a new QR code with the given content and options.

Jump to

Keyboard shortcuts

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