httpEmbed

package module
v0.220103.1 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 4 Imported by: 0

README

go-HttpEmbed

取消http中使用embed嵌入静态资源时必须录入相对路径的问题

静态资源目录

D:\WORK\go\src\work\test\static\ui
D:\WORK\go\src\work\test\static\ui\page
D:\WORK\go\src\work\test\static\ui\page\index.html
D:\WORK\go\src\work\test\static\ui\page\main.wasm
D:\WORK\go\src\work\test\static\ui\page\wasm.js

http://127.0.0.1:8080/ui/index.html 打开index.html

package main

import (
	"embed"
	httpEmbed "github.com/cnwangfei/go-HttpEmbed"
	"github.com/gin-gonic/gin"
	"net/http"
)

//go:embed static/ui/page
var uiEmbed embed.FS

func main() {
	g := gin.Default()
	g.GET("")

	var e httpEmbed.Fs
	e.FS = &uiEmbed
	e.Path = "static/ui/page"
	g.StaticFS("/ui", http.FS(e))

	g.Run(":8080")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fs

type Fs struct {
	*embed.FS        // 静态资源
	Path      string // 设置embed文件到静态资源的相对路径,也就是embed注释里的路径
}

func (Fs) Open

func (f Fs) Open(name string) (fs.File, error)

Jump to

Keyboard shortcuts

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