bungo

package module
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 7 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ¶

BunGo logo

BunGo (Bundler 4 Go)

BunGo is a high-performance, fullstack, and idiomatic Go web framework designed to seamlessly bridge backend Go logic with frontend React (JSX) views. It eliminates the need for Node.js, npm, package.json, and complex external build pipelines by embedding everything you need right into your Go binary.

If you love the simplicity of Go backends but want the rich interactivity of React without the headache of managing a separate frontend ecosystem, BunGo is the framework for you.


📚 Documentation

For complete guides, usage patterns, and best practices, please refer to our new docs directory:

  1. Introduction to BunGo
  2. Installation & Setup
  3. Routing and Pages
  4. Templates and Layouts
  5. React Integration
  6. Security Layers
  7. CLI and Dev Tools
  8. Deployment Options

📦 Quick Start & Installation

You can instantly scaffold a fresh BunGo application using our dedicated CLI tool.

Important Note: To use the bungo CLI, your Go bin directory must be in your system's PATH. If you encounter a "command not found" error after installation, add $HOME/go/bin to your PATH (e.g., export PATH=$PATH:$HOME/go/bin in your .zshrc or .bashrc). For specific OS instructions, see the Installation Guide.

  1. Install the CLI once:

    go install github.com/piotr-nierobisz/BunGo/cmd/bungo@latest
    
  2. Scaffold a project and run the live-reload dev server:

    bungo init my-project
    cd my-project
    go mod tidy
    
    # Starts your server and continuously hot-reloads on changes!
    bungo dev
    

(For a native TypeScript integration, add --typescript to the init command).

For manual project setups without the CLI, refer to the Installation Guide.


TODOs

  • Improved documentation / wiki
  • Add unit tests
  • Cache resolved dependencies for faster startup
  • TypeScript support (.tsx/.ts views + CLI --typescript scaffold)
  • Production optimizations
  • Live reload for development (bungo dev)
  • More comments!
  • Add support for net/http ssl

Documentation ¶

Index ¶

Constants ¶

View Source
const DevWebSocketPort = 35729

DevWebSocketPort is the fixed port the bungo CLI listens on for live reload; must match injected client.

Variables ¶

This section is empty.

Functions ¶

func RenderTemplate ¶

func RenderTemplate(
	templatePath string,
	layoutPath string,
	inlineJS string,
	data map[string]any,
) (string, error)

RenderTemplate renders the page using optional layout composition.

templatePath is required: the page-specific .gohtml file. When layoutPath is empty, it is treated as a standalone page: scripts are injected and this template is executed.

layoutPath is optional: when set, it is the wrapper .gohtml that defines {{block "content" .}}. The template file is expected to define {{define "content"}}...{{end}}. Scripts are injected into the layout (e.g. before </head> or </body>), and the layout is executed so that the block is filled by the template's "content" definition.

Types ¶

type APIResponse ¶

type APIResponse struct {
	StatusCode int
	Body       any
}

APIResponse represents an API response

type ApiRoute ¶

type ApiRoute struct {
	Path          string
	Version       string
	Method        string
	SecurityLayer []string
	Handler       func(req *Request) (APIResponse, error)
}

ApiRoute represents a configuration for an API route

type Engine ¶

type Engine interface {
	Start(address string, srv *Server) error
}

Invoker represents the execution environment starting the server. We define it locally to avoid import cycle, since engine pkg depends on bungo

type PageRoute ¶

type PageRoute struct {
	Path          string
	Template      string
	Layout        string
	View          string
	SecurityLayer []string
	Handler       func(req *Request) (map[string]any, error)
}

PageRoute configures a single page route.

Template is required: the page-specific .gohtml file in layouts/ that holds the page content (and optionally {{define "content"}} when using a Layout).

Layout is optional: a wrapper .gohtml in layouts/ that defines {{block "content" .}}. When set, the Template is rendered inside that block, so you avoid repeating <html>, <head>, and <body> in every template. If empty, the Template is rendered as a standalone page.

View is optional: the corresponding .jsx/.tsx (or .js/.ts) entry in views/ to be compiled and injected into the page as a module script.

type Request ¶

type Request struct {
	Headers  map[string]string
	Params   map[string]string // URL and Query parameters
	Body     []byte
	Internal map[string]any // For passing context between Security Layers and Handlers
}

Request represents a framework-agnostic HTTP request

type SecurityLayer ¶

type SecurityLayer struct {
	Name    string
	Handler func(req *Request) bool
}

SecurityLayer represents a reusable security layer that can be applied to routes.

type Server ¶

type Server struct {
	Pages          map[string]PageRoute
	APIs           map[string]ApiRoute
	SecurityLayers map[string]SecurityLayer
	Engine         Engine
	WebDir         string
	DefaultLayout  string
}

Server is the central registry for the BunGo application.

func NewServer ¶

func NewServer(engine Engine, webDir string) *Server

NewServer initializes a new Server with the given engine and web directory

func (*Server) Api ¶

func (s *Server) Api(route ApiRoute)

Api registers a new API route

func (*Server) Page ¶

func (s *Server) Page(route PageRoute)

Page registers a new page route. Template is required; Layout and View are optional.

func (*Server) Security ¶

func (s *Server) Security(layer SecurityLayer)

Security registers a new security layer

func (*Server) Serve ¶

func (s *Server) Serve(port int) error

Serve starts the server on the specified port by delegating to the Engine

func (*Server) SetDefaultLayout ¶

func (s *Server) SetDefaultLayout(path string)

SetDefaultLayout sets the optional wrapper template used for all pages that do not set Layout on their PageRoute. The layout file must exist in webDir/layouts/ when webDir is non-empty.

Directories ¶

Path Synopsis
cmd
bungo command
aws module
gcp module
internal
dev

Jump to

Keyboard shortcuts

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