pkgassets

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2021 License: BSD-3-Clause, BSD-3-Clause Imports: 3 Imported by: 0

README

pkgassets

USAGE

    pkgassets [OPTIONS] VARIABLE_NAME DIR_HOLDING_ASSETS [VARIABLE_NAME DIR_HOLDING_ASSETS ...]

DESCRIPTION

pkgassets generates a Go source directory whos file assets are embedded in a map[string][]byte variable. This is useful where you want to embed web content, template source code, help docs and other assets that can be used for default behavior in a Go command line program or service.

The map content is harvested from directory holding the assets to be embedded. By default the path key starts with a slash and does not include the hosting directory (e.g. htdocs/index.html would become /index.html if htdocs was used to harvest assets). The prefix and suffix on the key can be modified based on pkgassets's command line options.

OPTIONS

-c	comment file to be included
-comment	comment file to be included
-example	display example(s)
-ext	Only include files with matching extension
-h	display help
-help	display help
-l	display license
-license	display license
-o	output filename
-output	output filename
-p	package name, if missing defauls to lowercase of variable name
-package	package name, if missing defauls to lowercase of variable name
-strip-prefix	strip the prefix from the map key
-strip-suffix	strip the suffix from the map key
-v	display version
-version	display version

EXAMPLES

    pkgassets MAP_VARAIBLE_NAME NAME_OF_DIRECTORY_HOLDING_ASSETS

This will result in a Go of type map[string][]byte holding the assets discovered by walking the directory tree provided. The map's key will represent a path (beginning with "/") pointing at the asset ingested.

    pkgassets DefaultSite htdocs

Assuming that htdocs held

  • index.html
  • css/site.css

In this example the htdocs directory will be crawled and all the files found harvested as a an asset. The path in the map will not include htdocs and would result in a Go source file like

    package defaultsite

    var DefaultSite = map[string][]byte{
        "/index.html": []byte{}, // ... the contents of index.html would be here ...
        "/css/site.css": []byte{}, // ... the contents of css/site.css would be here ...
    }

If a package name is not provided then the package name will a lowercase name of the map variable name (e.g. "var DefaultSite" becomes "package defaultsite"). Likewise if a output name is not provided then the file name will be the name of the package plus the ".go" extension.

Related examples: help, htdocs.

pkgassets v0.0.6

Documentation

Overview

pkgassets is a command line tool for harvesting directory contents (like website default files) and turning them into a Go package with a map of path and byte array of contents harvested.

@Author R. S. Doiel, <rsdoiel@caltechlibrary.edu>

Copyright (c) 2021, Caltech All rights not granted herein are expressly reserved by Caltech.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

This section is empty.

Variables

View Source
var (
	Version = cli.Version

	LicenseText = cli.LicenseText
)

Functions

func ByteArrayToDecl

func ByteArrayToDecl(src []byte) (string, error)

ByteArrayToDecl converts the contents of the file pointed to by fname into a Byte array declaration.

Types

This section is empty.

Jump to

Keyboard shortcuts

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