goblet

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2019 License: MIT Imports: 8 Imported by: 9

README

goblet

Build Status Coverage Status GoDoc Go Report Card

library and cmd tools set for managment assets like go-bindata or go-assets

install

To use asset builder, get all packages.

go get -u github.com/deadcheat/goblet/...

To only use generated file, get single package

go get -u github.com/deadcheat/goblet

How to use

Simply create asset from a directory
goblet /pass/to/your/assets
Create asset with go:generate comment
goblet -g /pass/to/your/assets
Name different package name and output different directory
goblet -p mypackage -o ./mypackage /pass/to/your/assets
Help Command

On command-line, goblet acts as asset builder like as go-assets-builder or go-bindata

NAME:
   goblet - make a binary contain some assets

USAGE:
   goblet [global options] command [command options] [arguments...]

VERSION:
   1.3.0

COMMANDS:
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --expression value, -e value  Regular expressions you want files to contain
   --generate, -g                If set, generate go:generate line to outputfile
   --ignore-dotfiles             If set, ignore dotfiles(i.e. '.gitkeep')
   --exclude-empty-dir           If set, ignore dotfiles(i.e. '.gitkeep')
   --name value, -n value        Variable name for output assets (default: "Assets")
   --out value, -o value         Output file name, result will be displaed to standard-out when it's skipped
   --package value, -p value     Package name for output (default: "main")
   --help, -h                    show help
   --version, -v                 print the version

Examples

see example repo dir for full of codes.

http static file

Generated asset is generated as implementation of http.FileSystem

	http.Handle("/", http.FileServer(assetsbin.Assets))
	log.Println("start server localhost:3000")
	if err := http.ListenAndServe(":3000", nil); err != nil {
		log.Fatal(err)
	}

Sometimes we changed root on http request from "/" such as "/statics/", goblet.FileSystem has WithPrefix func.

	http.Handle("/static/", http.FileServer(assetsbin.Assets.WithPrefix("/static/")))
	log.Println("start server localhost:3000")
	if err := http.ListenAndServe(":3000", nil); err != nil {
		log.Fatal(err)
	}
reading config file with config library like github.com/spf13/viper

goblet.File has bytes.Reader, so you can use goblet.File directly

	viper.SetConfigType("toml")
	f, _ := configbin.Assets.File("/config/configfile.toml")
	viper.ReadConfig(f)
	var s Server
	_ = viper.UnmarshalKey("server", &s)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileNotFound error when file is not found
	ErrFileNotFound = errors.New("specified file is not found")
)

Functions

This section is empty.

Types

type File

type File struct {
	Path       string
	Data       []byte
	FileMode   os.FileMode
	ModifiedAt time.Time
	// contains filtered or unexported fields
}

File file system model for each files

func NewFile

func NewFile(p string, d []byte, m os.FileMode, mat time.Time) *File

NewFile return new file

func NewFromFileInfo

func NewFromFileInfo(fi os.FileInfo, p string, d []byte) *File

NewFromFileInfo return new file

func (*File) Close

func (f *File) Close() error

Close implement for io.Closer

func (*File) IsDir

func (f *File) IsDir() bool

IsDir implement for os.FileInfo

func (*File) ModTime

func (f *File) ModTime() time.Time

ModTime implement for os.FileInfo

func (*File) Mode

func (f *File) Mode() os.FileMode

Mode implement for os.FileInfo

func (*File) Name

func (f *File) Name() string

Name implement for os.FileInfo

func (*File) Read

func (f *File) Read(data []byte) (int, error)

Read for io.Reader

func (*File) Readdir

func (f *File) Readdir(count int) ([]os.FileInfo, error)

Readdir implement for http.File

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek for io.Seeker

func (*File) Size

func (f *File) Size() int64

Size implement for os.FileInfo

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat implement for http.File

func (*File) Sys

func (f *File) Sys() interface{}

Sys implement for os.FileInfo

type FileSystem

type FileSystem struct {
	Dirs  map[string][]string
	Files map[string]*File
	// contains filtered or unexported fields
}

FileSystem exported to a generated asset file

func NewFS

func NewFS(dirs map[string][]string, files map[string]*File) *FileSystem

NewFS return newFS FileSystem pointer

func (*FileSystem) Exists

func (fs *FileSystem) Exists(name string) bool

Exists check whether file exists

func (*FileSystem) File

func (fs *FileSystem) File(filename string) (*File, error)

File returns file struct

func (*FileSystem) Open

func (fs *FileSystem) Open(name string) (http.File, error)

Open file from name

func (*FileSystem) ReadDir

func (fs *FileSystem) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir return all files in specified directory

func (*FileSystem) ReadFile

func (fs *FileSystem) ReadFile(filename string) ([]byte, error)

ReadFile read file and return []byte like as ioutil.ReadFile

func (*FileSystem) WithIgnoredPrefix added in v1.0.2

func (fs *FileSystem) WithIgnoredPrefix(prefix string) (newFs *FileSystem)

IgnoredPrefix set FileSystem.pathPrefix and return FileSystem itself

func (*FileSystem) WithPrefix

func (fs *FileSystem) WithPrefix(prefix string) (newFs *FileSystem)

WithPrefix set FileSystem.pathPrefix and return FileSystem itself

Directories

Path Synopsis
cmd
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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