This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
.go.json Project Configuration File Format
Joe Fitzgerald edited this page Feb 22, 2017
·
2 revisions
🚨 Note: this is not currently implemented, and is a proposal 🚨
Developers use a variety of editors when working with Go. Historically, each editor has its own format for editor-specific configuration (of the editor itself and for projects within the editor).
- For many go projects, a project-specific (or editor-specific) settings file will not be required (i.e. editors should have sane defaults that obviate the need for configuration, and should guide new users to achieve configurable actions idiomatically and without having to customize configuration)
- For many go projects, allow configuration of project-specific settings in a single file that can be understood by multiple editors
- Where possible, delegate to the user's environment rather than relying on a configuration file
- Prefer simplicity over complexity (apply the 80/20 rule)
- We cannot replace editor-specific configuration in its entirety
- We cannot address every possible configuration scenario
- We should not require every user to have a
.go.json
file in their filesystem
.go.json
JSON
Anywhere within $GOPATH/src
. If one is found outside $GOPATH/src
and a src
directory is present in the same directory, the project will be assumed to be a gb
project.
Template variables are specified using the text/template
variable format (e.g. {{.VariableName}}
) and are used to modify cmd
, args
, and cwd
fields with the results of variable expansion. The following variables are supported:
-
{{.File}}
: The full path to the file currently being edited -
{{.PackagePath}}
: The full path to the package containing the file currently being edited -
{{.ProjectDirectory}}
: The full path to the directory containing the.go
configuration file -
{{.DebugMode}}
:test
ordebug
, depending on whether a user would like to debug tests or the running application -
{{.DebugPort}}
: The port that should be used to communicate with the debugger
An example .go
configuration file:
{
"env": {
"somevar": "someval",
"GOPATH": "~/projects/project1:~/projects/common"
},
"build": {
"cmd": "go",
"args": [
"build"
],
"cwd": "{{.ProjectDirectory}}"
},
"test": {
"cmd": "go",
"args": [
"test",
"./..."
],
"cwd": "{{.ProjectDirectory}}"
},
"format": {
"cmd": "goimports",
"args": [
"-e",
"--srcdir",
"{{.PackagePath}}"
],
"cwd": "{{.PackagePath}}"
},
"lint": {
"cmd": "gometalinter",
"args": [
"--vendor",
"--disable-all",
"--enable=vet",
"--enable=vetshadow",
"--enable=golint",
"--enable=ineffassign",
"--enable=goconst",
"--tests",
"--json",
"."
],
"cwd": "{{.PackagePath}}"
},
"run": {
"cmd": "go run *.go",
"cwd": "{{.PackagePath}}"
},
"debug": {
"cmd": "dlv",
"args": [
"{{.DebugMode}}",
"--headless=true",
"--listen=localhost:{{.DebugPort}} --log"
]
}
}