ginDist

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: MIT Imports: 9 Imported by: 0

README

ginDist

基于gin框架将前端静态文件打包到二进制中

安装

go get github.com/golang-middleware/ginDist

目录

├── dist
│   └── index.html
├── go.mod
├── go.sum
└── main.go

使用

默认访问http://localhost:8888/ 访问的是index.html文件

package main

import (
	"embed"
	"github.com/gin-gonic/gin"
	"github.com/golang-middleware/ginDist"
)

//go:embed dist
var fs embed.FS

func main() {
	r := gin.Default()

	// 如果想要修改默认访问的资源,需要你手动指定
	//paths := map[string]string{"/": "home.html"}
	//r.Use(ginDist.Static(fs, paths))

	r.Use(ginDist.Default(fs))
	r.Run(":8888")
}

编译

go build
编译完了之后,静态资源可以删除了

方案提出链接

https://github.com/golang/go/issues/35950

Documentation

Overview

Package ginDist @Time : 2021/10/30 下午4:29 @Author: Jtyoui@qq.com @note : Content-Type 标头告诉客户端实际返回的内容的内容类型 @URL : 参考地址: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types

Package ginDist @Time : 2021/10/20 上午10:12 @Author: Jtyoui@qq.com @note : 打包前端文件dist中间件

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default added in v1.1.0

func Default(efs embed.FS) gin.HandlerFunc

Default 默认index.html静态文件

func Static added in v1.1.0

func Static(efs embed.FS, paths map[string]string) gin.HandlerFunc

Static 多路径静态文件

Types

This section is empty.

Jump to

Keyboard shortcuts

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