resource

package
v0.0.0-...-c117620 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: GPL-3.0 Imports: 4 Imported by: 4

README

Resource Package

This is a simple Go package to help a utility find its resources. In the java world, I'd typically package files into my Jar, but have no equivalent for Go other than compiling the files into the executable as []bytes.

Status

This is a first cut an what I need to get by. An interface, Locator, is provided, which translates between resource names and full path names. A singe kind of Locator is provided, which will search a list of provided root paths for a resource.

Example use:

// second arg is appended to $GOPATH/src, and added after first arg
loc := resource.NewPathLocator([]string{"/usr/local/share/go/mypackage"}, "/github.com/rwtodd/mypackage")

// look up the licence file in our resources
license, err := loc.Path("LICENSE") 

Future Plans

Other types of Locator are possible: one that hashes all the available files in a set of directories so the lookup is very quick, etc. I plan to provide these as the need arises.

Documentation

Overview

The resource package helps an application locate files important to the program. In this early state, the package searches $GOPATH, but eventually more features will be added.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locator

type Locator interface {
	// Path translates a resource name into
	// a full filesystem path.
	Path(rsc string) (string, error)
}

A Locator knows how to find resources

func NewPathLocator

func NewPathLocator(paths []string, goPathRepo string) Locator

NewPathLocator creates a Locator which uses a fixed set of base paths to find a given resource. Set a non-empty goPathRepo to append $GOPATH/src/$goPathRepo to the list of paths. It is not considered an error if $GOPATH isn't defined.

Jump to

Keyboard shortcuts

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