framework

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 13 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 + /app 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
β”œβ”€β”€ app/
β”‚   └──  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)
}

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]interface{})

func Run ΒΆ

func Run(params *InitParams) *http.ServeMux

Types ΒΆ

type InitParams ΒΆ

type InitParams struct {
	Mux                        *http.ServeMux
	IsDevMode                  bool
	EsbuildOpts                api.BuildOptions
	AutoRegisterTemplateRoutes bool
}

type RouterSetupFunc ΒΆ

type RouterSetupFunc struct {
	BasePath string
	Handler  func(mux *http.ServeMux, db interface{}, 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