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
- Get started with all the defaults:
package main
import (
"net/http"
"github.com/bencbradshaw/framework"
)
func main() {
http.ListenAndServe(":2025", framework.Run(nil))
}
- 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)
}