Documentation ¶
Overview ¶
Package frontend helps development Go web server that uses SPA (Single Page Application) style web frontend.
In development mode, it runs frontend's dev server automatically.
In production mode, it returns prebuilt assets from go:embed
This package works with Next.js, Vue.js, SvelteKit, Solid.js.
Index ¶
- Variables
- func MustNewSPAHandler(ctx context.Context) http.Handler
- func MustNewSPAHandlerFunc(ctx context.Context) http.HandlerFunc
- func NewSPAHandler(ctx context.Context) (http.Handler, error)
- func NewSPAHandlerFunc(ctx context.Context) (http.HandlerFunc, error)
- func SetFrontAsset(assets embed.FS, o Opt)
- func SetOption(o Opt)
- type FrameworkType
- type Mode
- type Opt
Constants ¶
This section is empty.
Variables ¶
var ErrDir = errors.New("path is dir")
var ErrPackageJsonNotFound = errors.New("package.json not found")
Functions ¶
func MustNewSPAHandler ¶
MustNewSPAHandler is similar to NewSPAHandler but this calls panic when error.
func MustNewSPAHandlerFunc ¶
func MustNewSPAHandlerFunc(ctx context.Context) http.HandlerFunc
MustNewSPAHandlerFunc is similar to NewSPAHandlerFunc but this calls panic when error.
func NewSPAHandler ¶
NewSPAHandler is handler that handles SPA contents.
Use with net/http:
h, err := NewSPAHandler(ctx) http.Handle("/", h)
func NewSPAHandlerFunc ¶
func NewSPAHandlerFunc(ctx context.Context) (http.HandlerFunc, error)
NewSPAHandlerFunc is handler function that handles SPA contents.
Use with chi:
r := chi.NewRouter() c, err := NewSPAHandlerFunc(ctx) http.NotFound(h)
func SetFrontAsset ¶
Types ¶
type FrameworkType ¶
type FrameworkType int
const ( AutoDetect FrameworkType = iota NextJS VueJS SvelteKit SolidJS NotFound )
func FrameworkTypeString ¶
func FrameworkTypeString(s string) (FrameworkType, error)
FrameworkTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func FrameworkTypeValues ¶
func FrameworkTypeValues() []FrameworkType
FrameworkTypeValues returns all values of the enum
func (FrameworkType) IsAFrameworkType ¶
func (i FrameworkType) IsAFrameworkType() bool
IsAFrameworkType returns "true" if the value is listed in the enum definition. "false" otherwise
func (FrameworkType) String ¶
func (i FrameworkType) String() string
type Mode ¶
type Mode int
func ModeString ¶
ModeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
type Opt ¶
type Opt struct { FrontEndFolderName string // Frontend application folder name that contains package.json. Default value is "frontend" FrontEndFolderPath string // Absolute frontend application folder that contains package.json. SkipRunningDevServer bool // Even if development mode, frontend-go doesn't run dev server FrameworkType FrameworkType // NextJS, VueJS, SvelteKit, SolidJS is available instead of auto detect DistFolder string // Specify dist folder instead of auto detect Port uint16 // Specify port instead of auto detect DevServerCommand string // Specify dev server command instead of auto detect FallbackPath string // Specify fallback file path. Default is "index.html" }
Opt specifies frontend configuration.
frontend-go assumes frontend project is in "frontend" folder. And it tries to get other config as soon as possible. If you changed dist folder or build scripts and so on, use Opt and pass to NewSPAHandler, NewSPAHandlerFunc