framework

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2025 License: MIT Imports: 13 Imported by: 0

README

Why Framework

  • Easily create html pages for SEO optimized "public" facing pages
  • AND create one or multiple JavaScript SPA without running any NodeJS process
    • Utilizing esbuild's Go module, there is no need for Webpack, Babel, Vite, Rollup, or any separate process apart from your Go server. TypeScript, JavaScript, JSX, TSX, and CSS
  • Accompanying JavaScript library for frontend development
    • Server-sent events for auto-reload while developing
    • Router, state management, and elements
  • Twig templates for HTML rendering
  • Native Go HTTP module

create your project

├── app
│   └── src
│        └── index.ts // this is the default entry point for your frontend application
├── templates // twig/html templates - auto register with `name.route.twig`
│   ├── index.twig // "/" default route
│   └── about.route.twig // "/about" route
├── static // build files from esbuild are placed here
├── main.go // your go application - see below for example
  • you now can have:
    • html routes served from /templates
    • frontend javascript bundled and served
  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 Render

func Render(w http.ResponseWriter, name 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