fs

package
v0.0.0-...-ff244ab Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package fs contains an HTTP file system that works with zip contents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteAsset

func DeleteAsset(asset *Asset)

DeleteAsset removes a dynamic asset.

func Foreach

func Foreach(predicate func(name, context string, f *Asset))

Foreach iterates on the dynamic assets.

func Open

func Open(name string, context ...string) (*bytes.Reader, error)

Open returns a bytes.Reader for an asset in the given context, or the default context if no context is given.

func Register

func Register(zipData string)

Register registers zip contents data, later used to initialize the statik file system.

func RegisterCustomExternals

func RegisterCustomExternals(cache Cache, opts []AssetOption, maxTryCount int) error

RegisterCustomExternals ensures that the assets are in the cache, and load them from their source if they are not yet available.

Types

type Asset

type Asset struct {
	AssetOption
	Etag        string `json:"etag"`
	NameWithSum string `json:"name_with_sum"`
	Mime        string `json:"mime"`
	// contains filtered or unexported fields
}

Asset holds unzipped read-only file contents and file metadata.

func Get

func Get(name string, context ...string) (*Asset, bool)

Get returns a dynamic asset for the given context, or the default context if no context is given.

func (*Asset) GzipReader

func (f *Asset) GzipReader() *bytes.Reader

GzipReader returns a bytes.Reader for the gzipped content of the asset.

func (*Asset) GzipSize

func (f *Asset) GzipSize() string

GzipSize returns the size of the gzipped version of the asset.

func (*Asset) Reader

func (f *Asset) Reader() *bytes.Reader

Reader returns a bytes.Reader for the asset content (no compression).

func (*Asset) Size

func (f *Asset) Size() string

Size returns the size in bytes of the asset (no compression).

type AssetOption

type AssetOption struct {
	Name     string `json:"name"`
	Context  string `json:"context"`
	URL      string `json:"url"`
	Shasum   string `json:"shasum"`
	IsCustom bool   `json:"is_custom,omitempty"`
}

AssetOption is used to insert a dynamic asset.

type Cache

type Cache interface {
	Get(key string) (io.Reader, bool)
	Set(key string, data []byte, expiration time.Duration)
	RefreshTTL(key string, expiration time.Duration)
}

Cache is an interface for caching the assets in memory.

Jump to

Keyboard shortcuts

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