gas

package module
Version: v0.0.0-...-a3a07b0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2014 License: MIT Imports: 7 Imported by: 34

README

#GAS

GAS (Gopath ASsets) is a lib to load resources (images, text, videos, templates, etc...) using GOPATH.

#Installing

go get github.com/andrebq/gas

#Using

file, err := gas.Open("import/path/to/file.png")
// This is similar to os.Open but it search the GOPATH variable for possible locations
// the first one to match is used
//
// The matched file will be: $GOPATH/src/import/path/to/file.png
//
// Same idea of "GOPATH" variables but for resources and not only go packages.
//
// If the file isn't found on gopath, this will search the current folder for the location.

The behavior is well defined:

First it search the gopath (prepending the src base folder), if the file isn't found then it will search the current folder.

#License

Released under MIT License, see LICENSE for more information

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(file string) (string, error)

Return the absolute filepath for the requested resource or return an error if not found

func IsNotFound

func IsNotFound(err error) bool

Return true if the error represents a NotFound error

func MustAbs

func MustAbs(file string) string

MustAbs ensure that the given file is present in the system, if the file can't be found, this will call panic giving the reason

func Open

func Open(file string) (io.ReadCloser, error)

Open the file for reading or returns an error

For more information, see the FS type

func ReadFile

func ReadFile(file string) ([]byte, error)

ReadFile return the contents of the file at the given gopath

func Refresh

func Refresh()

Refresh the internal FS to reflect possible changes in the UnitedFS

Types

type FS

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

func FromDirs

func FromDirs(dirs []string) *FS

FromDirs return a new filesystem that searchs for the request file on the specified dirs

This make a copy of the input array

func GopathFS

func GopathFS() *FS

Create a new GopathFS instance

func UnitedFS

func UnitedFS() *FS

Create a FS which is the combination of the GopathFS and the current folder note that the current folder don't require the "src" sub-folder

func (*FS) Abs

func (fs *FS) Abs(file string, allowDir bool) (abs string, err error)

Find the absolute path for the required file.

The returned string is OS depended. If the desired file isn't present in any possible location returns NotFound error.

func (*FS) Open

func (fs *FS) Open(file string) (r io.ReadCloser, err error)

Open the resource for reading

type NotFound

type NotFound string

Used to indicat that the file wasn't found in any possible location

func (NotFound) Error

func (n NotFound) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL