frontend

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 11 Imported by: 0

README

frontend

Embed front-end web static files in gin and add routing.


Example of use

import "gitee.com/the_sun_light/common_pkg/gin/frontend"

//go:embed user
var staticFS embed.FS

func setFrontendRouter(r *gin.Engine) error {
	var (
		isUseEmbedFS   = true
		htmlDir        = "user/home"
		configFile     = "user/home/config.js"
		modifyConfigFn = func(content []byte) []byte {
			// modify config code
			return content
		}
	)

	err := frontend.New(staticFS, isUseEmbedFs, htmlDir, configFile, modifyConfigFn).SetRouter(r)
	if err != nil {
		panic(err)
	}
}

Note: in the above example, user is the directory where the front-end is located, the static file index.html is in the user/home directory. If isUseEmbedFS is false and apiBaseUrl is set in the configuration file, cross-host access is supported.

Documentation

Overview

Package frontend embeds the frontend static file and adds routing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoOpenBrowser

func AutoOpenBrowser(visitURL string) error

AutoOpenBrowser auto open browser

Types

type FrontEnd

type FrontEnd struct {
	// contains filtered or unexported fields
}

FrontEnd is the frontend router configuration

func New

func New(staticFS embed.FS, isUseEmbedFS bool, htmlDir string, configFile string, modifyConfigFn func(content []byte) []byte) *FrontEnd

New create a new frontend

func (*FrontEnd) SetRouter

func (f *FrontEnd) SetRouter(r *gin.Engine) error

SetRouter set frontend router

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL