github.com/robertkrimen/dogbag/dogbag/zipbag

Bundle data with your Go executable (Take your data to Go)


Install
go get github.com/robertkrimen/dogbag/dogbag/zipbag

Documentation

dogbag

-- Command dogbag is way to bundle data with your Go executable.

(Take your data to Go)

To dogbag a file and use it:

   # Create template.tmpl_dogbag.go from the file template.tmpl:
   $ dogbag template.tmpl .
   ...
   // var template []byte
   template := template_tmpl()

To dogbag a directory and use it

   # Create assets_dogbag.go from the directory ./assets:
   $ dogbag ./assets .
   ...
   // dogbag is a Bag
   dogbag, err := assets()

Install

 go get github.com/robertkrimen/dogbag/dogbag

Usage

 dogbag <input> <output> [...]

     <input> Can be a file, directory, or - (stdin)
     If a file, then a filebag will be built
     If a directory, then a zipbag will be built
     If omitted, the default is stdin (and a filebag will be built)

     <output> Can be a file, directory, or - (stdout)
     If a directory, then an <input>.go file will be put in the directory
     If omitted, the default is stdout

     -function=""      The name of the function returning the dogbag
     -package=""       The package to put the dogbag .go file in
     -empty=false      Make an empty (zip) dogbag (for development)
     -fmt=true         Postprocess through gofmt
     -usage=false      More help: Bag interface description, etc.

--

Zipbag Usage

# To dogbag a directory:
$ dogbag ./assets

// assets.go:
dogbag, err := assets()
// dogbag is a Bag, with the following interface:
SetBase(path string) error

SetBase will set the base directory that the bag is to serve assets from.

The bag will ignore what it has in memory and serve from disk instead.

The format of the path argument is platform-specific (filepath).

Deploy(path string) error

Deploy will deploy the bag to disk, triggering SetBase in the process.

The directory that the bag deploys to is guarded by the SHA1 digest of bag. That is, a different version of the same program deploying to the same path will not collide with a previous version.

The format of the path argument is platform-specific (filepath).

 Path(path ...string) string

Path will transform a bag path into a file path.

    path := bag.Path("tmpl", "main.tmpl")
    // path => ""

    bag.Deploy("/home/example")
    path := bag.Path("tmpl", "main.tmpl")
    // path => /home/example/bag.f7d9.../tmpl/main.tmpl

    path = bag.Path("data/image.png")
    // path => /home/example/bag.f7d9.../data/image.png

    path = bag.Path()
    // path => /home/example/bag.f7d9.../

The path arguments for this method are always UNIX-style (forward-slash). The return value is a platform specific path (via filepath).

This method is ONLY useful after either SetBase or Deploy has run. Otherwise, since the bag does not exist on disk, this method will always return "" (You can use this behavior to test if a bag has been deployed, if necessary)

 Open(path ...string) (io.ReadCloser, error)

Open will open the asset at the given bag path for reading, whether the asset is in memory or on disk.

    file, err := bag.Open("tmpl/main.tmpl")
    if err != nil {
        return err
    }
    defer file.Close()

-- godocdown http://github.com/robertkrimen/godocdown