Back to

Package packr

Latest Go to latest

The latest major version is v2.

Published: Mar 8, 2020 | License: MIT | Module:



const Version = "v2.8.0"

Version of Packr


var (
	// ErrResOutsideBox gets returned in case of the requested resources being outside the box
	// Deprecated
	ErrResOutsideBox = fmt.Errorf("can't find a resource outside the box")

func PackBytes

func PackBytes(box string, name string, bb []byte)

PackBytes packs bytes for a file into a box. Deprecated

func PackBytesGzip

func PackBytesGzip(box string, name string, bb []byte) error

PackBytesGzip packets the gzipped compressed bytes into a box. Deprecated

func PackJSONBytes

func PackJSONBytes(box string, name string, jbb string) error

PackJSONBytes packs JSON encoded bytes for a file into a box. Deprecated

type Box

type Box struct {
	Path            string            `json:"path"`
	Name            string            `json:"name"`
	ResolutionDir   string            `json:"resolution_dir"`
	DefaultResolver resolver.Resolver `json:"default_resolver"`
	// contains filtered or unexported fields

Box represent a folder on a disk you want to have access to in the built Go binary.

func Folder

func Folder(path string) *Box

Folder returns a Box that will NOT be packed. This is useful for writing tests or tools that need to work with a folder at runtime.

func New

func New(name string, path string) *Box

New returns a new Box with the name of the box and the path of the box.

func NewBox

func NewBox(path string) *Box

NewBox returns a Box that can be used to retrieve files from either disk or the embedded binary. Deprecated: Use New instead.

func (*Box) AddBytes

func (b *Box) AddBytes(path string, t []byte) error

AddBytes sets t in by the given path

func (*Box) AddString

func (b *Box) AddString(path string, t string) error

AddString converts t to a byteslice and delegates to AddBytes to add to

func (*Box) Bytes

func (b *Box) Bytes(name string) []byte

Bytes is deprecated. Use Find instead

func (*Box) Find

func (b *Box) Find(name string) ([]byte, error)

Find returns either the byte slice of the requested file or an error if it can not be found.

func (*Box) FindString

func (b *Box) FindString(name string) (string, error)

FindString returns either the string of the requested file or an error if it can not be found.

func (*Box) Has

func (b *Box) Has(name string) bool

Has returns true if the resource exists in the box

func (*Box) HasDir

func (b *Box) HasDir(name string) bool

HasDir returns true if the directory exists in the box

func (*Box) List

func (b *Box) List() []string

List shows "What's in the box?"

func (*Box) MustBytes

func (b *Box) MustBytes(name string) ([]byte, error)

MustBytes is deprecated. Use Find instead.

func (*Box) MustString

func (b *Box) MustString(name string) (string, error)

MustString is deprecated. Use FindString instead

func (*Box) Open

func (b *Box) Open(name string) (http.File, error)

Open returns a File using the http.File interface

func (*Box) Resolve

func (b *Box) Resolve(key string) (file.File, error)

Resolve will attempt to find the file in the box, returning an error if the find can not be found.

func (*Box) SetResolver

func (b *Box) SetResolver(file string, res resolver.Resolver)

SetResolver allows for the use of a custom resolver for the specified file

func (*Box) String

func (b *Box) String(name string) string

String is deprecated. Use FindString instead

func (*Box) Walk

func (b *Box) Walk(wf WalkFunc) error

Walk will traverse the box and call the WalkFunc for each file in the box/folder.

func (*Box) WalkPrefix

func (b *Box) WalkPrefix(prefix string, wf WalkFunc) error

WalkPrefix will call box.Walk and call the WalkFunc when it finds paths that have a matching prefix

type File

type File = file.File

File has been deprecated and file.File should be used instead

type Pointer

type Pointer struct {
	ForwardBox  string
	ForwardPath string

Pointer is a resolvr which resolves a file from a different box.

func (Pointer) Resolve

func (p Pointer) Resolve(box string, path string) (file.File, error)

Resolve attempts to find the file in the specific box with the specified key

type WalkFunc

type WalkFunc = packd.WalkFunc

WalkFunc is used to walk a box

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier