static

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 29 Imported by: 0

README

Package Static

This package help to manage static file router in an API to embedded files into the go binary api. This package requires packr tools, golib/router & go Gin Tonic API Framework.

Example of implementation

We will work on an example of file/folder tree like this :

/
  bin/
    api/
      config/
      routers/
        static/
          get.go
  static/
    static/
      ...some_static_files...

in the get.go file, we will implement the static package call :

package static

import (
    "github.com/gin-gonic/gin"
	"github.com/gobuffalo/packr"
	"github.com/nabbar/golib/static"

    "myapp/release"
    "myapp/bin/api/config"
    "myapp/bin/api/routers"
)

const UrlPrefix = "/static"

func init() {
	staticStcFile := static.NewStatic(false, UrlPrefix, packr.NewBox("../../../../static/static"), GetHeader)

	staticStcFile.SetDownloadAll()
	staticStcFile.Register(routers.RouterList.Register)
}

func GetHeader(c *gin.Context) {
    // any function to return global & generic header (like CSP, HSTS, ...)
}

Documentation

Index

Constants

View Source
const (
	ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgStatic
	ErrorFileInfo
	ErrorFileOpen
	ErrorFiletemp
	ErrorFileNotFound
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Static

type Static interface {
	RegisterRouter(route string, register librtr.RegisterRouter, router ...ginsdk.HandlerFunc)
	RegisterRouterInGroup(route, group string, register librtr.RegisterRouterInGroup, router ...ginsdk.HandlerFunc)

	RegisterLogger(log func() liblog.Logger)

	SetDownload(pathFile string, flag bool)
	SetIndex(group, route, pathFile string)
	GetIndex(group, route string) string
	SetRedirect(srcGroup, srcRoute, dstGroup, dstRoute string)
	GetRedirect(srcGroup, srcRoute string) string
	SetSpecific(group, route string, router ginsdk.HandlerFunc)
	GetSpecific(group, route string) ginsdk.HandlerFunc

	IsDownload(pathFile string) bool
	IsIndex(pathFile string) bool
	IsIndexForRoute(pathFile, group, route string) bool
	IsRedirect(group, route string) bool

	Has(pathFile string) bool
	List(rootPath string) ([]string, liberr.Error)
	Find(pathFile string) (io.ReadCloser, liberr.Error)
	Info(pathFile string) (os.FileInfo, liberr.Error)
	Temp(pathFile string) (libiot.FileProgress, liberr.Error)

	Map(func(pathFile string, inf os.FileInfo) error) liberr.Error
	UseTempForFileSize(size int64)

	Monitor(ctx libctx.FuncContext, cfg montps.Config, vrs libver.Version) (montps.Monitor, error)

	Get(c *ginsdk.Context)
	SendFile(c *ginsdk.Context, filename string, size int64, isDownload bool, buf io.ReadCloser)
}

func New added in v1.8.6

func New(ctx libctx.FuncContext, content embed.FS, embedRootDir ...string) Static

Jump to

Keyboard shortcuts

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