lets-gopher-exercise

command module
v0.0.0-...-c1ce984 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

README

= Let's Gopher

IMPORTANT: This code repository is used as an example project for the training https://github.com/bmuschko/go-project-automation/["Go project automation"]. It's not intended for real-world use. For a full-fledged Go project generator have a look at https://github.com/bmuschko/letsgopher[this repository].

Let's Gopher is a simple, yet flexible project generator for Go. The tool uses templates available in the directory `~/.lets-gopher/templates`. Users can create templates manually by creating directories and files as desired. Templates hosted on Git repositories can be downloaded and added to the template directory.

This project is based on https://github.com/golang/go/wiki/Modules[Go Modules]. Please enable Go Modules by setting the environment variable `export GO111MODULES=on`.

== Installing a template

The project doesn't come with any templates out-of-the-box. You need to install them yourself. The tool will report missing templates in the console output.

----
go run main.go
2019/01/17 13:30:20 No templates found!
----

Templates can only be installed from a Git URL. To install a template, run the `install` command with the `--url` parameter. The tool will clone the repository.

----
go run main.go install --url="https://github.com/bmuschko/go-helloworld-template.git"
2019/01/17 13:32:21 Cloning template from repository https://github.com/bmuschko/go-helloworld-template.git
----

Subsequent `install` operations pull the latest change from the originating repository.

----
go run main.go install --url="https://github.com/bmuschko/go-helloworld-template.git"
2019/01/17 13:32:25 Pulling latest changes for existing template in /Users/bmuschko/.lets-gopher/templates/go-helloworld-template
----

Alternatively, you can just create a new directory under `~/.lets-gopher/templates` and populate it with files.

== Generating projects from a template

You can generate a new project from the template if at least one template can be found. The files of a selected template will be written to `$GOPATH/src/<base-path>`.

----
go run main.go
? What template would you like to use to generate a project?  [Use arrows to move, type to filter]
❯ go-helloworld-template
You choose "go-helloworld-template"
? What base path would like to use? github.com/bmuschko/helloworld
You choose "github.com/bmuschko/helloworld"
Generating project in "/Users/bmuschko/go/src/github.com/bmuschko/helloworld"
----

== Configuring default conventions

You might get tired of having to spell out certain default values. For example, you'll likely want to use the same domain whenever you generate a new project. The tool can be configured in the file `~/.lets-gopher/.lets-gopher.yml`.

[source,yaml]
----
domain: github.com/bmuschko
----

Configured default values are consumed as applicable but can still be reconfigured.

----
go run main.go
? What template would you like to use to generate a project?  [Use arrows to move, type to filter]
❯ go-helloworld-template
You choose "go-helloworld-template"
? What base path would like to use? (github.com/bmuschko/go-helloworld-template)
You choose "github.com/bmuschko/go-helloworld-template"
Generating project in "/Users/bmuschko/go/src/github.com/bmuschko/go-helloworld-template"
----

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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