pina-golada

module
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: MIT

README

Pina-Golada /pi:nɑ:-goʊlɑ:dɑ:/

License Go Report Card Build and Tests Go Reference Release

pina-golada

Introducing the pina-golada

Pina-Golada is a tool and framework to package assets (files and directories) into an executable binary. To be precise, it is for executables that are created by the Go compiler.

For this to work, pina-golada scans your Go source files for well known annotations and creates Go source code that contains the referenced assets. In your program, you are able to access the assets in memory or write them to disk by simplify defining an easy interface to work against. Pina-Golada will take care of the rest to provide the files and directories in the final build, without you having to render them in the source code yourself.

Tools that are known to use pina-golada to package assets into their program code are:

  • watchful - tool to measure the disruption caused by a change to a Cloud Foundry environment
  • gonut - portable tool to help you verify whether you can push a sample app to Cloud Foundry

Installation

Installation options are either using Homebrew or a convenience download script.

  • On macOS systems, a Homebrew tap is available to install pina-golada:

    brew install homeport/tap/pina-golada
    
  • Use a convenience script to download the latest release to install it in a suitable location on your local machine (works for Linux and macOS systems):

    curl -fsL https://git.io/JtMNA | bash
    

Usage example

In case your Go project needs assets packaged into your program, you can use pina-golada and the following code stub:

package assets

import (
 "github.com/homeport/pina-golada/pkg/files"
)

// Provider is the provider instance to access the assets framework
var Provider ProviderInterface

// ProviderInterface is the interface that provides the assets
// @pgl(injector=Provider)
type ProviderInterface interface {
  
  // GetConfigFile returns an in-memory version of the asset
  // @pgl(asset=/assets/default-config.yaml&compressor=tar)
  GetConfigFile() (dir files.Directory , e error)
}

Prior to the build, run pina-golada generate to create a generated Go source file, which contains your assets. To clean up any generated file, use pina-golada cleanup. If you fancy more details, enable the verbose mode using --verbose. This works for generate as well as cleanup. In addition to the verbose parameter, you can specify the annotation parser you want to use by providing the parser tag value. Here are the currently supported parser values:

  • property
    • Example: @pgl(asset=/my/path&compressor=tar)
  • csv
    • Example: @pgl(asset,/my/path;compressor,tar)
  • build-tag
    • Example: +pgl asset,/my/path compressor,tar

Contributing

We are happy to have other people contributing to the project. If you decide to do that, here's how to:

  • get a Go development environment with version 1.12 or greater
  • fork the project
  • create a new branch
  • make your changes
  • open a PR.

Git commit messages should be meaningful and follow the rules nicely written down by Chris Beams:

The seven rules of a great Git commit message

  1. Separate subject from body with a blank line
  2. Limit the subject line to 50 characters
  3. Capitalize the subject line
  4. Do not end the subject line with a period
  5. Use the imperative mood in the subject line
  6. Wrap the body at 72 characters
  7. Use the body to explain what and why vs. how
Running test cases and binaries generation

There are multiple make targets, but running all does everything you want in one call.

make all
Test it with Linux on your macOS system

Best way is to use Docker to spin up a container:

docker run \
  --interactive \
  --tty \
  --rm \
  --volume $GOPATH/src/github.com/homeport/pina-golada:/go/src/github.com/homeport/pina-golada \
  --workdir /go/src/github.com/homeport/pina-golada \
  golang:1.12 /bin/bash
Git pre-commit hooks

Add a pre-commit hook using this command in the repository directory:

cat <<EOS | cat > .git/hooks/pre-commit && chmod a+rx .git/hooks/pre-commit
#!/usr/bin/env bash

set -euo pipefail
make test

EOS

License

Licensed under MIT License

Directories

Path Synopsis
cmd
golada
Package main hosts the starting point of the pain-golada application and overall simply initializes the cobra framework.
Package main hosts the starting point of the pain-golada application and overall simply initializes the cobra framework.
internal
golada/builder
Package builder hosts the builder interfaces and implementation which are responsible of creating the go source classes that implement the pina-golada interfaces.
Package builder hosts the builder interfaces and implementation which are responsible of creating the go source classes that implement the pina-golada interfaces.
golada/cmd
Package cmd hosts the different cobra commands pina-golada offers.
Package cmd hosts the different cobra commands pina-golada offers.
golada/logger
Package logger hosts the small logger wrapper internally used by pina-golada to encapsulate the verbose logic to one instance.
Package logger hosts the small logger wrapper internally used by pina-golada to encapsulate the verbose logic to one instance.
pkg
annotation
Package annotation hosts the general annotation framework used by pina-golada.
Package annotation hosts the general annotation framework used by pina-golada.
compressor
Package compressor hosts the compressor logic used by pina-golada to compress the assets into binary form.
Package compressor hosts the compressor logic used by pina-golada to compress the assets into binary form.
files
Package files hosts the interfaces that pina-golada uses to represent a virtual file system to de-couple the application from the host file system after an initial read.
Package files hosts the interfaces that pina-golada uses to represent a virtual file system to de-couple the application from the host file system after an initial read.
files/paths
Package paths hosts the interface used by pina-golada to parse and concat relative and absolute file paths.
Package paths hosts the interface used by pina-golada to parse and concat relative and absolute file paths.
generator
Package generator hosts the generator interfaces, which are the base for building go source files from runtime.
Package generator hosts the generator interfaces, which are the base for building go source files from runtime.
inspector
Package inspector hosts the interfaces which analyses existing go source files and fetches interface commands and variable setup.
Package inspector hosts the interfaces which analyses existing go source files and fetches interface commands and variable setup.

Jump to

Keyboard shortcuts

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