assetfs

package module
v0.0.0-...-ff57fdc Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2017 License: MIT Imports: 7 Imported by: 57

README

AssetFS

AssetFS is a golang package and defined AssetFS Interface that abstracts the access to files.

It has a default implementation that based on FileSystem, which could be used in development, load required files directly from disk.

If you want to compile all required files into a binary and load files from from binary, you could refer our bindatafs

Usage

import "github.com/qor/assetfs"

func main() {
	// Default implemention based on filesystem, you could overwrite with other implemention, for example bindatafs will do this.
	assetfs := assetfs.AssetFS

	// Register path to AssetFS
	assetfs.RegisterPath("/web/app/views")

	// Prepend path to AssetFS
	assetfs.PrependPath("/web/app/views")

	// Get file's content with name from path `/web/app/views`
	assetfs.Asset("filename.tmpl")

	// List matched files from assetfs
	assetfs.Glob("*.tmpl")

	// NameSpace return namespaced filesystem
	namespacedFS := assetfs.NameSpace("asset")
	namespacedFS.RegisterPath("/web/app/myspecialviews")
	namespacedFS.PrependPath("/web/app/myspecialviews")
	// Will lookup file with name "filename.tmpl" from path `/web/app/myspecialviews` but not `/web/app/views`
	namespacedFS.Asset("filename.tmpl")
	namespacedFS.Glob("*.tmpl")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetAssetFS

func SetAssetFS(fs Interface)

SetAssetFS set assetfs

Types

type AssetFileSystem

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

AssetFileSystem AssetFS based on FileSystem

func (*AssetFileSystem) Asset

func (fs *AssetFileSystem) Asset(name string) ([]byte, error)

Asset get content with name from assetfs

func (*AssetFileSystem) Compile

func (fs *AssetFileSystem) Compile() error

Compile compile assetfs

func (*AssetFileSystem) Glob

func (fs *AssetFileSystem) Glob(pattern string) (matches []string, err error)

Glob list matched files from assetfs

func (*AssetFileSystem) NameSpace

func (fs *AssetFileSystem) NameSpace(nameSpace string) Interface

NameSpace return namespaced filesystem

func (*AssetFileSystem) PrependPath

func (fs *AssetFileSystem) PrependPath(pth string) error

PrependPath prepend path to view paths

func (*AssetFileSystem) RegisterPath

func (fs *AssetFileSystem) RegisterPath(pth string) error

RegisterPath register view paths

type Interface

type Interface interface {
	PrependPath(path string) error
	RegisterPath(path string) error
	Asset(name string) ([]byte, error)
	Glob(pattern string) (matches []string, err error)
	Compile() error

	NameSpace(nameSpace string) Interface
}

Interface assetfs interface

func AssetFS

func AssetFS() Interface

AssetFS get AssetFS

Jump to

Keyboard shortcuts

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