guikit

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 24 Imported by: 0

README

GUIKit

A high-performance, full-stack Go web framework featuring reactive Live-Components, a custom GML markup engine, and an embedded database.

Features

  • Reactive Live-Components: Real-time DOM patching over thread-safe WebSockets, inspired by LiveView architectures.
  • GML Markup Engine: A custom lexical parser and AST evaluator for a clean, component-driven template syntax.
  • Embedded Database: Deep integration with ultimate_db for seamless persistence and session management without external dependencies.
  • Production-Grade Security: Built-in Content Security Policy (CSP) noncing, path-traversal guards, and strict HTTP headers to prevent XSS and file-system exploits.
  • In-Memory Caching: High-performance template caching to eliminate disk I/O on active routes.
  • Virtual File System: Package your entire application (templates, assets, and database) into a single .gweb zip archive for trivial deployment.

Installation

GUIKit requires Go 1.25.10. Initialize your module and fetch GUIKit alongside its custom database dependency:

go mod init guikit
go get github.com/gorilla/websocket
go get github.com/gddisney/ultimate_db
go get github.com/gddisney/guikit
go mod tidy

Quick Start

1. Initialize the Engine (main.go)
package main

import (
	"log"
	"guikit"
)

func main() {
	// Initialize the framework with DB and WAL file paths
	engine, err := guikit.New("app.db", "app.wal")
	if err != nil {
		log.Fatalf("Failed to initialize GUIKit: %v", err)
	}

	// Define a protected route
	engine.Get("/", func(c *guikit.Context) {
		c.Data["Title"] = "Welcome to GUIKit"
		engine.Render(c, "views/index")
	})

	// Run the CLI / Server
	engine.Run()
}

2. Create a View (views/index.gml)
<wrapper "views/layout.gml">
	<h1 class="text-2xl font-bold">{{ .Title }}</h1>
	<p>This is a fast, secure, and reactive web interface running on GUIKit.</p>
</wrapper>

CLI Usage

GUIKit includes a built-in command-line interface for packing and serving your application seamlessly.

Serve Locally

Run your application in development mode on a specified port:

go run main.go serve 8080

Pack for Production

Bundle your entire application into a .gweb virtual file system archive:

go run main.go pack . build/app.gweb

Serve an Archive

Deploy by serving assets and routes directly out of a packed .gweb file:

go run main.go serve build/app.gweb 8080

Security & Architecture

GUIKit is hardened out-of-the-box for production stability:

  • CSP Noncing: Every request generates a unique cryptographic nonce applied to all inline scripts via internal middleware to mitigate XSS vulnerabilities.
  • Path Traversal Prevention: The GML engine strictly sanitizes all <wrapper> and <import> paths to restrict directory traversal escapes.
  • Concurrent Write Safety: WebSocket connections are entirely thread-safe to prevent memory corruption and race condition panics under high traffic.
  • Dead-Connection Sweeping: Automatic heartbeats (ping/pong) and failed client pruning cleanly sweep resources behind load balancers.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppFS fs.FS

Functions

This section is empty.

Types

type AssignNode added in v1.1.3

type AssignNode struct {
	Path       string
	Expression Expr
	Op         string
}

func (AssignNode) Execute added in v1.1.3

func (an AssignNode) Execute(ctx *ExecContext) error

type BinaryExpr added in v1.1.3

type BinaryExpr struct {
	Left  Expr
	Op    string
	Right Expr
}

func (BinaryExpr) Eval added in v1.1.3

func (be BinaryExpr) Eval(ctx *ExecContext) interface{}

type BuiltinFunc added in v1.1.3

type BuiltinFunc func(ctx *ExecContext, args []interface{}) (interface{}, error)

type CallExpr added in v1.1.3

type CallExpr struct {
	Name string
	Args []Expr
}

func (CallExpr) Eval added in v1.1.3

func (ce CallExpr) Eval(ctx *ExecContext) interface{}

type Context

type Context struct {
	W        http.ResponseWriter
	R        *http.Request
	Data     map[string]interface{}
	CspNonce string
}

type DMLInstruction added in v1.1.3

type DMLInstruction struct {
	Action   string `json:"action"` // "append", "remove", "addClass", "removeClass", "setValue"
	TargetID string `json:"target_id"`
	Value    string `json:"value"`
}

type Element

type Element struct {
	Tag        string
	Attributes map[string]string
	Children   []Node
}

func (Element) Eval

func (e Element) Eval() string

type ExecContext added in v1.1.3

type ExecContext struct {
	Component  *ScriptComponent
	Payload    map[string]string
	Locals     map[string]interface{}
	DB         *ultimate_db.DB
	ORM        *ultimate_db.ORM
	DMLActions []DMLInstruction
}

func (*ExecContext) ResolvePath added in v1.1.3

func (ctx *ExecContext) ResolvePath(path string) interface{}

func (*ExecContext) SetPath added in v1.1.3

func (ctx *ExecContext) SetPath(path string, val interface{})

type Expr added in v1.1.3

type Expr interface {
	Eval(ctx *ExecContext) interface{}
}

type ExprStmt added in v1.2.1

type ExprStmt struct{ Expression Expr }

func (ExprStmt) Execute added in v1.2.1

func (es ExprStmt) Execute(ctx *ExecContext) error

type ForNode added in v1.1.3

type ForNode struct {
	IteratorKey string
	IterableKey string
	Body        []ScriptNode
}

func (ForNode) Execute added in v1.1.3

func (fn ForNode) Execute(ctx *ExecContext) error

type GUIKit

type GUIKit struct {
	DB  *ultimate_db.DB
	ORM *ultimate_db.ORM
	Mux *http.ServeMux
	// contains filtered or unexported fields
}

func New

func New(db *ultimate_db.DB, orm *ultimate_db.ORM) (*GUIKit, error)

func (*GUIKit) Broadcast

func (gk *GUIKit) Broadcast(event string, payload interface{})

func (*GUIKit) Get

func (gk *GUIKit) Get(pattern string, handler func(c *Context))

func (*GUIKit) GetGlobal

func (gk *GUIKit) GetGlobal(key string) (interface{}, bool)

func (*GUIKit) GetGlobalMap

func (gk *GUIKit) GetGlobalMap() map[string]interface{}

func (*GUIKit) GetNonce

func (gk *GUIKit) GetNonce(r *http.Request) string

func (*GUIKit) GetSession

func (gk *GUIKit) GetSession(id uint64) string

func (*GUIKit) HandleWebSocket

func (gk *GUIKit) HandleWebSocket(w http.ResponseWriter, r *http.Request)

func (*GUIKit) Post

func (gk *GUIKit) Post(pattern string, handler func(c *Context))

func (*GUIKit) RegisterComponent

func (gk *GUIKit) RegisterComponent(comp LiveComponent)

func (*GUIKit) Render

func (gk *GUIKit) Render(c *Context, viewPath string)

func (*GUIKit) Run

func (gk *GUIKit) Run()

func (*GUIKit) SecureHeaders

func (gk *GUIKit) SecureHeaders(next http.HandlerFunc) http.HandlerFunc

func (*GUIKit) SetGlobal

func (gk *GUIKit) SetGlobal(key string, value interface{})

func (*GUIKit) SetSession

func (gk *GUIKit) SetSession(id uint64, key string, value string) error

type IfNode added in v1.1.3

type IfNode struct {
	Condition Expr
	Body      []ScriptNode
	ElseBody  []ScriptNode
}

func (IfNode) Execute added in v1.1.3

func (in IfNode) Execute(ctx *ExecContext) error

type IncomingEvent

type IncomingEvent struct {
	CompID string            `json:"id"`
	Event  string            `json:"event"`
	Data   map[string]string `json:"data"`
}

type LiteralExpr added in v1.1.3

type LiteralExpr struct{ Value interface{} }

func (LiteralExpr) Eval added in v1.1.3

func (le LiteralExpr) Eval(ctx *ExecContext) interface{}

type LiveComponent

type LiveComponent interface {
	ID() string
	Render() string
}

type Node

type Node interface {
	Eval() string
}

type OutgoingPatch

type OutgoingPatch struct {
	CompID string `json:"id"`
	HTML   string `json:"html"`
}

type Parser

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

func NewParser

func NewParser(src string) *Parser

func (*Parser) Parse

func (p *Parser) Parse() []Node

func (*Parser) TokenText added in v1.2.2

func (p *Parser) TokenText() string

type ReturnNode added in v1.1.3

type ReturnNode struct{ Expression Expr }

func (ReturnNode) Execute added in v1.1.3

func (rn ReturnNode) Execute(ctx *ExecContext) error

type ScriptBlock added in v1.1.3

type ScriptBlock struct{ Statements []ScriptNode }

type ScriptComponent added in v1.1.3

type ScriptComponent struct {
	Id         string
	GmlPath    string
	ScriptPath string
	State      map[string]interface{}
	Handlers   map[string]*ScriptBlock
	Functions  map[string]UserFunction
	Db         *ultimate_db.DB
	Orm        *ultimate_db.ORM
	// contains filtered or unexported fields
}

func LoadScriptComponent added in v1.1.6

func LoadScriptComponent(gk *GUIKit, id string, viewPath string) (*ScriptComponent, error)

func (*ScriptComponent) ID added in v1.1.3

func (sc *ScriptComponent) ID() string

func (*ScriptComponent) InvokeEvent added in v1.1.3

func (sc *ScriptComponent) InvokeEvent(name string, data map[string]string) ([]DMLInstruction, error)

func (*ScriptComponent) Render added in v1.1.3

func (sc *ScriptComponent) Render() string

type ScriptNode added in v1.1.3

type ScriptNode interface {
	Execute(ctx *ExecContext) error
}

type ScriptParser added in v1.1.3

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

func NewScriptParser added in v1.1.3

func NewScriptParser(src string) *ScriptParser

func (*ScriptParser) Parse added in v1.1.3

func (p *ScriptParser) Parse(sc *ScriptComponent, namespace string) error

func (*ScriptParser) TokenText added in v1.2.2

func (p *ScriptParser) TokenText() string

type SessionRecord

type SessionRecord struct {
	ID         uint64 `json:"id"`
	SessionKey string `json:"session_key"`
	Value      string `json:"value"`
}

type Text

type Text string

func (Text) Eval

func (t Text) Eval() string

type ThreadSafeConn

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

func (*ThreadSafeConn) Close

func (s *ThreadSafeConn) Close() error

func (*ThreadSafeConn) WriteJSON

func (s *ThreadSafeConn) WriteJSON(v interface{}) error

func (*ThreadSafeConn) WriteMessage

func (s *ThreadSafeConn) WriteMessage(messageType int, data []byte) error

type UserFunction added in v1.1.3

type UserFunction struct {
	Params []string
	Body   []ScriptNode
}

type VariableExpr added in v1.1.3

type VariableExpr struct{ Path string }

func (VariableExpr) Eval added in v1.1.3

func (ve VariableExpr) Eval(ctx *ExecContext) interface{}

Jump to

Keyboard shortcuts

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