static

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

README

go-static

Coverage Status Release Go Report Card CI

Library for embedding static files inside an application

Install as tool

go install github.com/osspkg/go-static/cmd/static@latest

Packaging

//go:generate static <DIR> <VAR>
  • DIR - Path to the static folder
  • VAR - A variable containing static.Reader interface

Example go code

package example

import (
	"fmt"

	"github.com/osspkg/go-static"
)

//go:generate static ./.. ui

var ui static.Reader

func run() {
	fmt.Println(ui.List())
}

License

BSD-3-Clause License. See the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	OctetStream = "application/octet-stream"
)

Variables

View Source
var (
	//ErrUndefinedFormat error
	ErrUndefinedFormat = errors.New("undefined format")
)

Functions

func DetectContentType

func DetectContentType(filename string, b []byte) string

func ResponseFile added in v1.3.3

func ResponseFile(w http.ResponseWriter, filename string) error

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache model

func New

func New() *Cache

New init cache

func (*Cache) FromBase64TarGZ

func (c *Cache) FromBase64TarGZ(v string) error

FromBase64TarGZ ...

func (*Cache) FromDir

func (c *Cache) FromDir(dir string) error

FromDir ...

func (*Cache) FromFile

func (c *Cache) FromFile(filename string) error

FromFile ...

func (*Cache) FromTarArchive

func (c *Cache) FromTarArchive(r io.Reader) error

FromTarArchive ...

func (*Cache) FromTarGZArchive

func (c *Cache) FromTarGZArchive(r io.Reader) error

FromTarGZArchive ...

func (*Cache) Get

func (c *Cache) Get(filename string) ([]byte, string)

Get getting file by name

func (*Cache) List

func (c *Cache) List() []string

List getting all files list

func (*Cache) Reset

func (c *Cache) Reset()

Reset clean cache

func (*Cache) ResponseWrite

func (c *Cache) ResponseWrite(w http.ResponseWriter, filename string) error

ResponseWrite write file to response

func (*Cache) Set

func (c *Cache) Set(filename string, v []byte)

Set setting data to cache

func (*Cache) ToBase64TarGZ

func (c *Cache) ToBase64TarGZ() (string, error)

ToBase64TarGZ ...

func (*Cache) ToFile

func (c *Cache) ToFile(filename string) error

ToFile ...

func (*Cache) ToTarArchive

func (c *Cache) ToTarArchive(w io.Writer) error

ToTarArchive ...

func (*Cache) ToTarGZArchive

func (c *Cache) ToTarGZArchive(w io.Writer) error

ToTarGZArchive ...

type Reader

type Reader interface {
	Get(filename string) ([]byte, string)
	List() []string

	ResponseWrite(w http.ResponseWriter, filename string) error
}

Directories

Path Synopsis
cmd
static command
example
demo
Code generated by github.com/osspkg/go-static.
Code generated by github.com/osspkg/go-static.

Jump to

Keyboard shortcuts

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