robertkrimen / smuggol

smuggol is a tool for physically importing Go code from one package to another

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

smuggol

-- import "github.com/robertkrimen/smuggol"

Package smuggol is a way to import Go code from one package to another.

While the normal Go import makes a "loose" connection to an external package (like a symlink), a smuggol import "physically" copies the package over (like a hardlink).

// Standard import, code is external and must resolved via "go get ..."
import (
    "github.com/robertkrimen/terst"
)

// After a smuggol import, code is local
import (
    . "./terst"
)

A smuggol import is useful for promoting code reuse while avoiding the breakage that can happen from future changes in behavior/correctness of the import package.

WARNING: Currently this package is fairly alpha-ish (API-wise), and is only public to support building of other tools (dbg-import, kilt-import, terst-import).

This package works by iterating through the .go files in a given import package and copying them to a subordinate package in the new host package. The files have the following comment at the top:

// This file was AUTOMATICALLY GENERATED by ... from ...

The name of the subordinate package is the same as the original import package.

Additionally, supporting .go files can be generated in the host package at the same time. This is done via a map[string]string , with each key/value pair representing a new file in the host package. Before being written to disk, the value is processed through "text/template" as a template with the following defined:

HostPackage     # The name of the host package
ImportPath      # The import path to the new import package
ImportPackage   # The name of the new import package

Usage

func Main

func Main(name, pkg string, extra map[string]string)

Main is the entry point for a command-line application.

It takes three arguments:

  1. The name of the application (for usage and error reporting, usually "-import")

  2. The import URL where the import package is located (e.g. "github.com/robertkrimen/terst")

  3. A final, optional parameter (pass nil unless you know what you're doing)

For example (terst-import):

func main() {
    smuggol.Main("terst-import", "github.com/robertkrimen/terst", nil)
}

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

About

smuggol is a tool for physically importing Go code from one package to another


Languages

Language:Go 100.0%