framework

package module
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: MIT Imports: 14 Imported by: 0

README ΒΆ

πŸš€ Framework

A minimal yet powerful web framework with builtin support for ssr html pages and SPA microfrontend splits

Features:

  • Simple routing & templating (HTML/Go templates)
  • Automatic microfrontend support for multiple SPAs
  • 1 Go dependency: esbuild
    • Use anything esbuild supports, like TypeScript, JavaScript, JSX, TSX, and CSS
  • NO NodeJS process required - no Webpack, Babel, Vite, Rollup, etc.
  • Clean /templates + /frontend folder structure
  • Autoreload when in development mode
  • Optional Accompanying JavaScript library for frontend development
    • Server Sent Events handler, Router, state management, and elements

🚦 Quickstart

1. Project Structure
your-project/
β”œβ”€β”€ templates/          # HTML templates & components
β”‚   β”œβ”€β”€ base.html       # Required: Base layout
β”‚   β”œβ”€β”€ entry.html      # Required: html snippet with js and css imports - autogenerated by esbuild on changes
β”‚   β”œβ”€β”€ index.html      # Required: Default html page
β”‚   β”œβ”€β”€ other.html      # "/other" route auto-registered
β”‚   └── app.subroute.html # "/app/" subroute auto-registered for the app - an easy way to add a new SPA
β”œβ”€β”€ static # bundled js files place here, you can .gitignore this
β”œβ”€β”€ frontend/
β”‚   └──  src/
β”‚      └── index.ts        # Your frontend entrypoint, customize and codesplit as needed
└── main.go             # Your server
  1. Get started with all the defaults:
package main

import (
	"net/http"

	"github.com/bencbradshaw/framework"
)

func main() {
	http.ListenAndServe(":2025", framework.Run(nil))
}
  1. Override the defaults:
package main

import (
	"net/http"
	"os"

	"github.com/bencbradshaw/framework"

	"github.com/evanw/esbuild/pkg/api"
)

func main() {
	mux := framework.Run(framework.InitParams{
		IsDevMode: false,
		AutoRegisterTemplateRoutes: false,
		EsbuildOpts: api.BuildOptions{
			EntryPoints: []string{"./app/src/my-app.tsx"},
		},
	})
	// add your own routes, the same as you would with the default mux
	mux.Handle("/api/hello-world", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello, World!"))
	}))
	http.ListenAndServe(":2025", mux)
}
🚧 In Progress Features
  • Support for Multiple Base Templates

    • Allow customization of JavaScript or CSS for different templates.
    • Your home page and about page might need different CSS or JS loaded.
  • Image Hosting

    • Provide built-in support for serving and managing images.
    • This will be simply a folder served with static files
  • Authentication Guard

    • Offer a middleware mechanism to enable developers to implement custom authentication logic for route handlers.
    • Rather than providing an authentication system, this will allow developers to use their own authentication systems that can tie into the framework.
  • Customizable Templates Directory

    • Ensure the /templates directory path can be configured as needed.
  • Template Naming Conventions

    • Clearly define and enforce a consistent naming pattern for templates to improve maintainability.
    • .html and subroute.html, base and entry. What do they mean and how do they work

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func Build ΒΆ

func Build(params InitParams) api.BuildResult

func RenderWithHtmlResponse ΒΆ added in v0.0.4

func RenderWithHtmlResponse(w http.ResponseWriter, templateName string, data map[string]any)

func Run ΒΆ

func Run(params InitParams) *http.ServeMux

Types ΒΆ

type InitParams ΒΆ

type InitParams = internal.InitParams

type RouterSetupFunc ΒΆ

type RouterSetupFunc struct {
	BasePath string
	Handler  func(mux *http.ServeMux, db any, devMode bool) http.Handler
}

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

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