static

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 12 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 (
	EMPTY_PARAMS errors.CodeError = iota + errors.MIN_PKG_Static
	EMPTY_PACKED
	INDEX_NOT_FOUND
	INDEX_REQUESTED_NOT_SET
	FILE_NOT_FOUND
)
View Source
const (
	FileIndex = "index.html"
)

Variables

This section is empty.

Functions

func IsCodeError

func IsCodeError() bool

Types

type Static

type Static interface {
	Register(register router.RegisterRouter)
	RegisterInGroup(group string, register router.RegisterRouterInGroup)

	SetDownloadAll()
	SetDownload(file string)
	IsDownload(file string) bool

	Has(file string) bool
	Find(file string) ([]byte, error)

	Health() errors.Error
	Get(c *gin.Context)
}

func NewStatic

func NewStatic(hasIndex bool, prefix string, box packr.Box, Header gin.HandlerFunc) Static

Jump to

Keyboard shortcuts

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