Files
golib/static
Nicolas JUHEL 0c1f4675fb Package IOUtils/BufferReadCloser:
- refactor package to allow closer for bytes.Buffer, bufio.Reader, bufio.Writer, bufio.ReadWriter
- implement ReadFrom, WriterTo, StringWriter, ReadRune, ReadByte, WriteByte
- allow specify a custom close function, called in close statement
- add NewBuffer (New declare as deprecated), NewReader, NewWriter, NewReadWriter to each types bytes / bufio
- remove call of Reset in close for ReadWriter: ambigous function (ambigous in bufio struct)

Package Static:
- replace BufferReadCloser New function to NewBuffer

Other:
- bump dependencies
2025-02-10 14:49:32 +01:00
..
2022-09-13 12:31:04 +02:00
2024-10-06 18:28:59 +02:00
2023-12-02 16:49:04 +01:00
2023-12-02 16:49:04 +01:00
2025-02-10 14:49:32 +01:00
2020-07-14 13:28:48 +02:00
2023-12-02 16:49:04 +01:00
2023-12-02 16:49:04 +01:00

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, ...)
}