velocity

package module
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 25 Imported by: 0

README

Velocity

A Laravel-inspired web framework for Go

Velocity brings joy and elegance to Go web development, without sacrificing Go's simplicity, performance, and type safety. Build web applications with expressive APIs and the speed of Go.

Why Velocity?

For Framework Users: Get familiar conventions and developer happiness you love, with Go's performance and concurrency.

For Go Developers: Skip the boilerplate and focus on building. Velocity provides a unified, elegant interface over common web development tasks.

Key Features
  • Single Binary: Deploy anywhere with zero dependencies
  • Type Safety: Full compile-time type checking with Go's type system
  • True Concurrency: Built-in goroutines and channels for high performance
  • Driver-Based Architecture: Swap implementations via config (Redis ↔ Memory, PostgreSQL ↔ MySQL)
  • Expressive DX: Familiar conventions, expressive APIs, and developer-friendly errors

Requirements

  • Go 1.25 or higher
  • Node.js 18+ (for frontend assets)

CLI Installation

Install the Velocity CLI to create and manage projects:

# Homebrew (macOS)
brew tap velocitykode/tap
brew install velocity

# Or with Go
go install github.com/velocitykode/velocity-cli@latest

Verify installation:

velocity version

Quick Start

Create a new project:

velocity new myapp
cd myapp
velocity serve

Your app runs at http://localhost:3000

Manual Setup

Add the framework to an existing project:

go get github.com/velocitykode/velocity
package main

import (
    "github.com/velocitykode/velocity/pkg/router"
    "github.com/velocitykode/velocity/pkg/log"
)

func main() {
    r := router.New()

    r.Get("/", func(c *router.Context) error {
        return c.JSON(200, map[string]string{
            "message": "Welcome to Velocity!",
        })
    })

    log.Info("Starting server on :4000")
    r.Run(":4000")
}

Feature Status

Package Status Description
async ✅ Complete Async primitives and concurrency patterns
auth ✅ Complete Authentication and session management
broadcast ✅ Complete Real-time event broadcasting
cache ✅ Complete Multi-driver caching (memory, file, redis)
config ✅ Complete Configuration management
crypto ✅ Complete Encryption and decryption
csrf ✅ Complete CSRF protection
events ✅ Complete Event system with listeners
log ✅ Complete Structured logging with multiple drivers
mail ✅ Complete Email sending with multiple drivers
orm ✅ Complete Database ORM with relationships
queue ✅ Complete Job queue system with workers
router ✅ Complete HTTP routing with middleware
scheduler ✅ Complete Task scheduling (cron-like)
storage ✅ Complete File storage abstraction
str ✅ Complete String manipulation utilities
testing ✅ Complete Testing helpers and utilities
validation ✅ Complete Input validation
view ✅ Complete Template rendering
vite ✅ Complete Vite.js integration for frontend
websocket ✅ Complete WebSocket support

Documentation

Full documentation at velocitykode.com/docs

Community

Philosophy

Velocity is built on three principles:

  1. Developer Happiness: Code should be a joy to write and read
  2. Convention over Configuration: Sensible defaults, configure only when needed
  3. Go's Strengths: Embrace simplicity, performance, and type safety

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

License

Velocity is open-source software licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// Core services — all exported for direct access
	Router     *router.VelocityRouterV2
	DB         *orm.Manager
	Auth       *auth.Manager
	Log        log.Logger
	Cache      *cache.Manager
	Crypto     crypto.Encryptor
	CSRF       *csrf.CSRF
	Events     events.Dispatcher
	Queue      queue.Driver
	Storage    *storage.Manager
	View       *view.Engine
	Scheduler  *scheduler.Scheduler
	Mail       mail.Mailer
	Exceptions *exceptions.Handler
	Validator  validation.Validator
	// contains filtered or unexported fields
}

App represents the Velocity application container. It owns all framework subsystem instances and provides them to the consumer.

func Default added in v0.9.5

func Default(opts ...Option) (*App, error)

Default creates a pre-configured App from env vars and sets it as the default for all package-level convenience functions. This provides a migration path from global singletons to explicit DI.

func New

func New(opts ...Option) (*App, error)

New creates a new Velocity application with all services initialized. Services are initialized in dependency order. If any required service fails to initialize, New returns an error — it never panics.

func NewTestApp added in v0.9.5

func NewTestApp(opts ...Option) (*App, error)

NewTestApp creates an App with in-memory services suitable for testing. Uses memory cache, memory queue, and console logger.

func (*App) Run

func (a *App) Run()

Run starts the application.

func (*App) Serve added in v0.9.5

func (a *App) Serve() error

Serve starts the HTTP server with signal handling and graceful shutdown.

func (*App) Shutdown added in v0.9.5

func (a *App) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down all services in reverse initialization order.

func (*App) Version

func (a *App) Version() string

Version returns the framework version.

type AuthConfig added in v0.9.5

type AuthConfig struct {
	DefaultGuard string                    // AUTH_GUARD
	Guards       map[string]GuardConfig    // Guard definitions
	Providers    map[string]ProviderConfig // Provider definitions
	BcryptCost   int                       // HASH_BCRYPT_COST, default 10
}

AuthConfig holds authentication configuration.

type CacheConfig added in v0.9.5

type CacheConfig struct {
	Driver        string // CACHE_DRIVER: memory, file, redis, database
	Prefix        string // CACHE_PREFIX, default "velocity_cache"
	Path          string // CACHE_PATH (for file driver)
	RedisHost     string // REDIS_HOST, default "127.0.0.1"
	RedisPort     int    // REDIS_PORT, default 6379
	RedisPassword string // REDIS_PASSWORD
	RedisDatabase int    // REDIS_DATABASE, default 0
}

CacheConfig holds cache configuration.

type Config added in v0.9.5

type Config struct {
	// App
	Name  string // APP_NAME, default "Velocity"
	Env   string // APP_ENV, default "development"
	Debug bool   // APP_DEBUG, default false
	Port  string // PORT, default "4000"
	Key   string // APP_KEY (used for crypto)

	// Database
	DB DBConfig

	// Auth
	Auth AuthConfig

	// Cache
	Cache CacheConfig

	// Log
	Log LogConfig

	// Queue
	Queue QueueConfig

	// Storage
	Storage StorageConfig

	// Session
	Session SessionConfig

	// View
	View ViewConfig

	// Crypto
	Crypto CryptoConfig

	// Mail
	Mail MailConfig
}

Config holds all configuration for a Velocity application. It replaces the scattered os.Getenv() calls across packages.

func ConfigFromEnv added in v0.9.5

func ConfigFromEnv() Config

ConfigFromEnv loads configuration from environment variables and .env file.

type CryptoConfig added in v0.9.5

type CryptoConfig struct {
	Key          string   // APP_KEY or CRYPTO_KEY
	Cipher       string   // CRYPTO_CIPHER, default "AES-256-GCM"
	PreviousKeys []string // CRYPTO_OLD_KEYS (comma-separated)
}

CryptoConfig holds encryption configuration.

type DBConfig added in v0.9.5

type DBConfig struct {
	Connection      string        // DB_CONNECTION: sqlite, postgres, mysql
	Host            string        // DB_HOST, default "127.0.0.1"
	Port            string        // DB_PORT, default per driver
	Database        string        // DB_DATABASE
	Username        string        // DB_USERNAME
	Password        string        // DB_PASSWORD
	Charset         string        // DB_CHARSET
	Collation       string        // DB_COLLATION
	Prefix          string        // DB_PREFIX
	Schema          string        // DB_SCHEMA
	SSLMode         string        // DB_SSL_MODE
	Timezone        string        // DB_TIMEZONE
	MaxIdleConns    int           // DB_MAX_IDLE_CONNS, default 10
	MaxOpenConns    int           // DB_MAX_OPEN_CONNS, default 100
	ConnMaxLifetime time.Duration // DB_CONN_MAX_LIFETIME, default 3600s
	LogQueries      bool          // DB_LOG_QUERIES
	SlowThreshold   time.Duration // DB_SLOW_QUERY_THRESHOLD
}

DBConfig holds database configuration.

type DiskConfig added in v0.9.5

type DiskConfig struct {
	Driver string // "local", "s3", "memory"
	Root   string // Root path for local driver
	// S3 fields
	Bucket   string
	Region   string
	Key      string
	Secret   string
	Endpoint string
	URL      string
}

DiskConfig holds configuration for a single storage disk.

type GuardConfig added in v0.9.5

type GuardConfig struct {
	Driver   string                 // "session" or "jwt"
	Provider string                 // Provider name
	Options  map[string]interface{} // Guard-specific options
}

GuardConfig holds configuration for an auth guard.

type JWTConfig added in v0.9.5

type JWTConfig struct {
	Secret           string // JWT_SECRET
	Algorithm        string // JWT_ALGO, default "HS256"
	TTL              int    // JWT_TTL in minutes, default 60
	RefreshTTL       int    // JWT_REFRESH_TTL in minutes, default 20160
	BlacklistEnabled bool   // JWT_BLACKLIST_ENABLED, default true
}

JWTConfig holds JWT guard configuration.

type LogConfig added in v0.9.5

type LogConfig struct {
	Driver string         // LOG_DRIVER: console, file
	Config map[string]any // Driver-specific config (e.g., "path" for file driver)
}

LogConfig holds logging configuration.

type MailConfig added in v0.9.5

type MailConfig struct {
	Driver string // MAIL_DRIVER: postmark, mailgun, log
}

MailConfig holds mail configuration.

type Option added in v0.9.5

type Option func(*App)

Option is a function that configures the App.

func WithConfig added in v0.9.5

func WithConfig(config Config) Option

WithConfig sets a custom configuration.

func WithPort added in v0.9.5

func WithPort(port string) Option

WithPort sets the server port.

type ProviderConfig added in v0.9.5

type ProviderConfig struct {
	Driver  string // "orm"
	Model   string // AUTH_MODEL, default "User"
	Options map[string]interface{}
}

ProviderConfig holds configuration for an auth user provider.

type QueueConfig added in v0.9.5

type QueueConfig struct {
	Driver        string // QUEUE_DRIVER: memory, redis, database
	RedisHost     string // QUEUE_REDIS_HOST, default "localhost"
	RedisPort     string // QUEUE_REDIS_PORT, default "6379"
	RedisPassword string // QUEUE_REDIS_PASSWORD
	RedisDB       string // QUEUE_REDIS_DB, default "0"
}

QueueConfig holds queue configuration.

type SessionConfig added in v0.9.5

type SessionConfig struct {
	Driver   string        // SESSION_DRIVER, default "cookie"
	Name     string        // SESSION_NAME, default "velocity_session"
	Lifetime int           // SESSION_LIFETIME in minutes, default 120
	Path     string        // SESSION_PATH, default "/"
	Domain   string        // SESSION_DOMAIN
	Secure   bool          // SESSION_SECURE, default true
	HttpOnly bool          // SESSION_HTTP_ONLY, default true
	SameSite http.SameSite // SESSION_SAME_SITE, default Lax
}

SessionConfig holds session configuration.

type StorageConfig added in v0.9.5

type StorageConfig struct {
	Default string                // STORAGE_DRIVER, default "local"
	Disks   map[string]DiskConfig // Disk configurations
}

StorageConfig holds storage configuration.

type ViewConfig added in v0.9.5

type ViewConfig struct {
	RootTemplate string // Path to root template or template string
	Version      string // Asset version for cache busting
	SSREnabled   bool   // Future: SSR support
	SSRURL       string // SSR server URL
}

ViewConfig holds view/Inertia configuration.

Directories

Path Synopsis
pkg
broadcast
Package broadcast provides a high-level broadcasting system for real-time communication built on top of the WebSocket package and supporting multiple drivers
Package broadcast provides a high-level broadcasting system for real-time communication built on top of the WebSocket package and supporting multiple drivers
cache/testing
Package testing provides test helpers for the cache package.
Package testing provides test helpers for the cache package.
exceptions
Package exceptions provides Laravel-style exception handling for Velocity.
Package exceptions provides Laravel-style exception handling for Velocity.
grpc
Package grpc provides a fluent API for building gRPC servers and HTTP gateways.
Package grpc provides a fluent API for building gRPC servers and HTTP gateways.
grpc/converters
Package converters provides utilities for converting between Go types and protobuf types.
Package converters provides utilities for converting between Go types and protobuf types.
grpc/grpcevents
Package grpcevents provides event types for gRPC operations.
Package grpcevents provides event types for gRPC operations.
grpc/interceptors
Package interceptors provides gRPC interceptors for Velocity applications.
Package interceptors provides gRPC interceptors for Velocity applications.
httpclient
Package httpclient provides an instrumented HTTP client for APM monitoring.
Package httpclient provides an instrumented HTTP client for APM monitoring.
log
mail/alldrivers
Package alldrivers imports all mail drivers to register them Import this package with _ to ensure all drivers are registered
Package alldrivers imports all mail drivers to register them Import this package with _ to ensure all drivers are registered
orm
router
Package router provides HTTP routing functionality for the Velocity framework.
Package router provides HTTP routing functionality for the Velocity framework.
str
trace
Package trace provides distributed tracing context helpers for APM instrumentation.
Package trace provides distributed tracing context helpers for APM instrumentation.

Jump to

Keyboard shortcuts

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