afs

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2019 License: MIT Imports: 15 Imported by: 0

README

Assets File System (AFS)

Another implementation of a virtual file system based on assets embedded in your code. The implementation uses zlib compression and base64 encoding.

Install

go get github.com/va-slyusarev/afs/...

Use case

  1. Add assets to the catalog;
  2. Run afs/afs utility by adjusting the appropriate parameters;
  3. Add generated class to your code and use.
package main

import (
	"log"
	"net/http"

	"github.com/va-slyusarev/afs"
	_ "your/path/which/was/generated" // init assets for afs
)

func main() {
	if fs, err := afs.GetAFS(); err == nil {
		log.Fatal(http.ListenAndServe(":8080", http.FileServer(fs)))
	}
}

See _example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(a ...*Asset)

Register registering assets for future inclusion in the AFS.

Types

type AFS

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

AFS Assets File System. This type implement http.FileSystem interface.

func GetAFS

func GetAFS() (*AFS, error)

GetAFS get and reload AFS.

func (*AFS) Add

func (afs *AFS) Add(a ...*Asset) error

Add new assets in AFS.

func (*AFS) Belong

func (afs *AFS) Belong(name string) bool

Belong file or dir belong to the AFS.

func (*AFS) ExecTemplate

func (afs *AFS) ExecTemplate(names []string, data interface{}) error

ExecTemplate performs text/template considering the content asset template. The result of the templating is put back into the asset content.

func (*AFS) Files

func (afs *AFS) Files() []string

Files get all sorted files and dir name from AFS.

func (*AFS) Open

func (afs *AFS) Open(name string) (http.File, error)

Open implements http.FileSystem.

func (*AFS) String

func (afs *AFS) String() string

String Stringer interface implementation. Files are displayed in sorted form.

type Asset

type Asset struct {
	AName  string // name of asset.
	Base64 string // content of asset base64 encoding.
	NoZLib bool   // The label of compression of content zlib.

	io.ReadSeeker
	// contains filtered or unexported fields
}

Asset the primary type that defines the asset. This type implements the necessary interfaces: http.File, os.FileInfo.

func (*Asset) Close

func (a *Asset) Close() error

Implements http.File. The rest is implemented within io.ReadSeeker.

func (*Asset) IsDir

func (a *Asset) IsDir() bool

func (*Asset) ModTime

func (a *Asset) ModTime() time.Time

func (*Asset) Mode

func (a *Asset) Mode() os.FileMode

func (*Asset) Name

func (a *Asset) Name() string

Implements os.FileInfo.

func (*Asset) Readdir

func (a *Asset) Readdir(count int) ([]os.FileInfo, error)

func (*Asset) Size

func (a *Asset) Size() int64

func (*Asset) Stat

func (a *Asset) Stat() (os.FileInfo, error)

func (*Asset) Sys

func (a *Asset) Sys() interface{}

Directories

Path Synopsis
web
CODE GENERATED AT 2019/04/23 16:56:01 BY AFS.
CODE GENERATED AT 2019/04/23 16:56:01 BY AFS.

Jump to

Keyboard shortcuts

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