lokstra

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README ΒΆ

Lokstra

Lokstra Logo

Modern Go Web Framework with Declarative Service Management

Documentation β€’ Quick Start β€’ Features β€’ Examples


What is Lokstra?

Lokstra is a versatile Go web framework that works in two ways:

🎯 As a Router (Like Echo, Gin, Chi)

Use Lokstra as a fast, flexible HTTP router with elegant middleware support.

r := lokstra.NewRouter("api")
r.GET("/", func() string {
    return "Hello, Lokstra!"
})
app := lokstra.NewApp("hello", ":3000", r)
app.Run(30 * time.Second)
πŸ—οΈ As a Framework (Like NestJS, Spring Boot)

Leverage lazy dependency injection, auto-generated routers, and configuration-driven deployment.

// Type-safe lazy DI
var userService = service.LazyLoad[*UserService]("user-service")

func handler() {
    users := userService.MustGet().GetAll()
}

Quick Start

1. Install CLI:

go install github.com/primadi/lokstra/cmd/lokstra@latest

2. Create Project:

# Interactive template selection
lokstra new myapp

# Or choose specific template
lokstra new blog-api -template 02_app_framework/01_medium_system

3. Run:

cd myapp
go run .

Done! Your app is running with routes already set up.

πŸ“¦ Using as Library
go get github.com/primadi/lokstra
package main

import "github.com/primadi/lokstra"

func main() {
    r := lokstra.NewRouter("api")
    r.GET("/", func() string {
        return "Hello, Lokstra!"
    })
    
    app := lokstra.NewApp("hello", ":3000", r)
    app.Run(30 * time.Second)
}

Features

⚑ Lokstra CLI
  • πŸ“¦ 6+ Production Templates - Router patterns & enterprise frameworks
  • πŸ”§ Auto-fix Imports - No manual configuration needed
  • πŸš€ Code Generation - Built-in autogen command for annotation-based templates
  • 🌐 Always Updated - Templates downloaded from GitHub
lokstra new myapp                           # Interactive
lokstra new myapp -template 01_router/...   # Specific template
lokstra autogen ./myproject                 # Generate code
🎯 Lazy Dependency Injection

Type-safe service loading with zero overhead:

var db = service.LazyLoad[*Database]("database")
users := db.MustGet().GetAll()  // Loaded once, cached forever
πŸ”„ Auto-Generated Routers

Generate REST APIs from service definitions:

service-definitions:
  user-service:
    type: user-service-factory

deployments:
  production:
    servers:
      api:
        published-services: [user-service]  # Auto-creates REST router!
πŸ—οΈ Flexible Deployment

One codebase, multiple topologies:

# Monolith
servers:
  all-in-one:
    published-services: [user-service, order-service]

# Microservices
servers:
  user-api:
    published-services: [user-service]
  order-api:
    published-services: [order-service]
πŸ“ Type-Safe Request Binding

Automatic validation with struct tags:

type CreateUserParams struct {
    Name  string `json:"name" validate:"required"`
    Email string `json:"email" validate:"required,email"`
}

func createUser(ctx *request.Context, params *CreateUserParams) error {
    // params already validated!
    user := db.CreateUser(params.Name, params.Email)
    return ctx.Api.Ok(user)
}

CLI Templates

Router Patterns
  • 01_router/01_router_only - Pure routing basics
  • 01_router/02_single_app - Production single app
  • 01_router/03_multi_app - Multiple apps server
Framework Patterns
  • 02_app_framework/01_medium_system - Domain-driven (2-10 entities)
  • 02_app_framework/02_enterprise_modular - DDD with bounded contexts
  • 02_app_framework/03_enterprise_router_service - Annotation-based enterprise

πŸ“– View All Templates β†’


Documentation


Why Lokstra?

vs Traditional Routers (Echo, Gin, Chi)

βœ… 29+ handler signatures - Ultimate flexibility
βœ… Clean middleware - Easy to compose
βœ… Type-safe DI - Optional, when you need it
βœ… Auto-generated routes - From services

vs DI Frameworks (Fx, Wire, Dig)

βœ… Type-safe - No any casting
βœ… Zero reflection - In hot path
βœ… Lazy loading - Memory efficient
βœ… Optional config - Start with code, scale with YAML

vs Full Frameworks (NestJS, Spring Boot)

βœ… Simpler - No decorators, no code generation required
βœ… Flexible - Use as router OR framework
βœ… Go-native - Idiomatic Go patterns
βœ… Deployment agnostic - Monolith β†’ microservices without code changes


Project Structure

lokstra/
β”œβ”€β”€ cmd/lokstra/              # CLI tool for scaffolding
β”œβ”€β”€ core/                     # Core framework
β”‚   β”œβ”€β”€ deploy/              # Deployment & config
β”‚   β”œβ”€β”€ registry/            # Service registry
β”‚   β”œβ”€β”€ request/             # Request handling
β”‚   └── router/              # HTTP routing
β”œβ”€β”€ project_templates/        # Project templates
β”‚   β”œβ”€β”€ templates.json       # Template registry
β”‚   β”œβ”€β”€ 01_router/          # Router patterns
β”‚   └── 02_app_framework/   # Framework patterns
β”œβ”€β”€ services/                # Built-in services
β”œβ”€β”€ middleware/              # Standard middleware
└── docs/                    # Documentation site

Community & Support


License

Apache 2.0 License - see LICENSE file for details.


Made with ❀️ by Primadi

⭐ Star on GitHub

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func NewApp ΒΆ

func NewApp(name string, addr string, routers ...Router) *app.App

Create a new App instance with given routers

func NewAppWithConfig ΒΆ added in v0.3.0

func NewAppWithConfig(name string, addr string, listenerType string,
	config map[string]any, routers ...Router) *app.App

Create a new App instance with given routers and custom listener configuration

func NewServer ΒΆ

func NewServer(name string, apps ...*app.App) *server.Server

Create a new Server instance with given apps

Types ΒΆ

type App ΒΆ

type App = app.App

type Handler ΒΆ added in v0.3.0

type Handler = request.Handler

type HandlerFunc ΒΆ

type HandlerFunc = request.HandlerFunc

type RequestContext ΒΆ added in v0.3.0

type RequestContext = request.Context

type Router ΒΆ added in v0.3.0

type Router = router.Router

func NewRouter ΒΆ added in v0.3.0

func NewRouter(name string) Router

Create a new Router instance

func NewRouterWithEngine ΒΆ added in v0.3.0

func NewRouterWithEngine(name string, engineType string) Router

Create a new Router instance with specific engine type (e.g., "default", "servemux")

type Server ΒΆ

type Server = server.Server

Directories ΒΆ

Path Synopsis
cmd
lokstra command
test-loader command
common
core
app
docs
internal
Package lokstra_registry provides a simplified API for the Lokstra registry system.
Package lokstra_registry provides a simplified API for the Lokstra registry system.
middleware
project_templates

Jump to

Keyboard shortcuts

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