static

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: MIT Imports: 22 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 (
	ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgStatic
	ErrorFileInfo
	ErrorFileOpen
	ErrorFiletemp
	ErrorFileNotFound
)

Variables

This section is empty.

Functions

func IsCodeError

func IsCodeError() bool

Types

type Static

type Static interface {
	RegisterRouter(route string, register librtr.RegisterRouter, router ...gin.HandlerFunc)
	RegisterRouterInGroup(route, group string, register librtr.RegisterRouterInGroup, router ...gin.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 gin.HandlerFunc)
	GetSpecific(group, route string) gin.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)

	StatusInfo() (name string, release string, hash string)
	StatusHealth() error
	StatusComponent(mandatory bool, message libsts.FctMessage, infoCacheTimeout, healthCacheTimeout time.Duration, sts libsts.RouteStatus)

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

func New added in v1.8.6

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

Jump to

Keyboard shortcuts

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