Documentation
¶
Overview ¶
Package frontend provides helpers for serving Vite-built frontend assets embedded in the Go binary via go:embed, plus a development proxy for hot-module reload during development.
It also contains two TypeScript code generators:
- GenerateTypes emits TS interfaces for Go structs with json tags.
- GenerateClient emits a typed, dependency-free fetch client from the router's named routes (see the documentation in client.go), reusing the same Go→TS type mapping.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateClient ¶
func GenerateClient(routes []*routing.Route, outFile string, opts ...ClientOption) error
GenerateClient generates a typed, dependency-free TypeScript fetch client for the given routes (typically router.Routes()) and writes it to outFile. See the package documentation above for the emission rules.
func GenerateTypes ¶
GenerateTypes generates TypeScript type declarations for Go structs annotated with `json` tags and writes the output to a .ts file. This is a lightweight, reflection-free source code generator.
frontend.GenerateTypes("app/models", "resources/ts/types.generated.ts")
Types ¶
type ClientOption ¶
type ClientOption func(*clientConfig)
ClientOption configures GenerateClient.
func WithRouteTypes ¶
func WithRouteTypes(routeName, requestGoType, responseGoType string) ClientOption
WithRouteTypes attaches request/response types to the named route. requestGoType and responseGoType are Go type expressions ("CreateUserRequest", "[]User", "map[string]bool", ...) converted with the same Go→TS mapping used by GenerateTypes. Pass "" to leave either side as `unknown`.
func WithTypesImport ¶
func WithTypesImport(module string) ClientOption
WithTypesImport sets the module specifier the generated client imports named interface types from, e.g. WithTypesImport("./types.generated"). Only the named (non-primitive) types actually referenced by WithRouteTypes are imported. Without this option, referenced named types are assumed to be declared elsewhere in the consuming project.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles serving frontend assets in both dev and production modes.
func New ¶
New creates a frontend Manager.
- In dev mode, requests are proxied to the Vite dev server.
- In production mode, assets are served from the embedded pubFS.
func (*Manager) Handler ¶
Handler returns an http.Handler that serves frontend assets. In dev mode it proxies to Vite; in prod it serves from the embedded FS.
func (*Manager) LoadManifest ¶
LoadManifest parses the Vite manifest.json from the given path. Call this during app startup in production.
type Option ¶
type Option func(*Manager)
Option configures the Manager.
func WithDevURL ¶
WithDevURL sets the Vite dev server URL (default: http://localhost:5173).