Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
- Go 1.14.2
- Mage 1.9.0
- GolangCI-Lint 1.26.0
- Add Visual Studio Code with Remote Containers support
- Add GitHub Actions workflow using Docker Compose
  • Loading branch information
pellared committed May 2, 2020
0 parents commit d6e014b
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or
// https://github.com/microsoft/vscode-dev-containers
{
"name": "Go",
"context": "..",
"dockerFile": "../Dockerfile",
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"go.gopath": "/go"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.go"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "apt-get update && apt-get install -y git"
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: build
on: push
jobs:
docker-compose:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: docker-compose up --abort-on-container-exit
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Visual Studio Code files
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/
68 changes: 68 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
linters-settings:
goimports:
local-prefixes: github.com/golang-templates/library
golint:
min-confidence: 0
misspell:
locale: US
nolintlint:
allow-leading-space: false # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: true # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
# default linters:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
# linters disabled by default:
- asciicheck
- bodyclose
- depguard
- dogsled
- dupl
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofmt
- goimports
- golint
- gomnd
- gomodguard
- goprintffuncname
- gosec
- interfacer
- lll
- maligned
- misspell
- nakedret
- nestif
- nolintlint
- prealloc
- rowserrcheck
- scopelint
- stylecheck
- testpackage
- unconvert
- unparam
- whitespace
- wsl
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-vscode.go"
]
}
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": []
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// gopls
"go.useLanguageServer": true,
// golangci-lint
"go.lintTool": "golangci-lint",
"go.lintFlags": [
"--fast"
]
}
43 changes: 43 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "All",
"type": "shell",
"command": "mage -v all",
"problemMatcher": [
"$go"
],
"group": "build"
},
{
"label": "Build",
"type": "shell",
"command": "mage -v build",
"problemMatcher": [
"$go"
],
"group": "build"
},
{
"label": "Lint",
"type": "shell",
"command": "mage -v lint",
"problemMatcher": [
"$go"
],
"group": "build"
},
{
"label": "Test",
"type": "shell",
"command": "mage -v test",
"problemMatcher": [
"$go"
],
"group": "build"
}
]
}
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Go
FROM golang:1.14.2
# mage
RUN GO111MODULE=on go get github.com/magefile/[email protected]
# golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Robert Pająk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[![Build Status](https://github.com/golang-templates/library/workflows/build/badge.svg)](https://github.com/golang-templates/library/actions?query=workflow%3Abuild)
[![GoDoc](https://godoc.org/github.com/golang-templates/library?status.svg)](https://godoc.org/github.com/golang-templates/library)
[![GitHub Release](https://img.shields.io/github/release/golang-templates/library.svg)](https://github.com/golang-templates/library/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/golang-templates/library)](https://goreportcard.com/report/github.com/golang-templates/library)

# Go Library Template

This is GitHub project template for a Go library. It has been created for ease-of-use for anyone who wants to:

- quickly get into Go without losing too much time on environment setup,
- create a new repoisitory with basic Continous Integration,
- write Go code on Linux, MacOS, Windows,
- use free tools.

It includes:

- editor config: [Visual Studio Code](https://code.visualstudio.com) with [Go](https://code.visualstudio.com/docs/languages/go) and [Remote Container](https://code.visualstudio.com/docs/remote/containers) support,
- dependency management: [Go Modules](https://github.com/golang/go/wiki/Modules),
- linter: [GolangCI-Lint](https://github.com/golangci/golangci-lint),
- build automation: [Mage](https://magefile.org), [Docker](https://docs.docker.com/engine), [Docker Compose](https://docs.docker.com/compose), [GitHub Actions](https://github.com/features/actions).

`Star` this project if you find it valuable and worth maintaining.

## Usage

1. Click the `Use this template` button (alt. clone or download this repository).
1. Replace all occurences of `golang-templates/library` to `your_org/repo_name` in all files.
1. Change [LICENSE](LICENSE) and [README.md](README.md).

### Setup Development Environment

Take notice that this project is build in a way that gives the developer a lot of freedom on the development environment setup. Below you can find proposals when using Visual Studio Code.

- **Bare metal:** Install Go, Visual Studio Code, Mage and GolangCI-Lint (see [Dockerfile](Dockerfile) for Mage and GolangCI-Lint installation commands).
- **Containers:** Install Docker, Visual Studio Code with Remote - Container extension. [Instructions](https://code.visualstudio.com/docs/remote/containers).
- **Remote via SSH**: [Instructions](https://code.visualstudio.com/docs/remote/ssh).

### Build

- Terminal: `mage -v all`.
- Visual Studio Code: `Terminal``Run Build Task... (CTRL+ALT+B)` → Select `All`.
- Terminal: `docker-compose up --abort-on-container-exit`. This command is executed by CI build (GitHub Action workflow).

### Maintainance

1. `Watch` this project to get notified about new releases, issues, etc.
1. Update Go, Mage and GolangCI-Lint version in [Dockerfile](Dockerfile). Take notice that when working on bare metal or via SSH, then you should also to do it manually on your machine.
1. Configure linters via [.golangci.yml](.golangci.yml).
1. Develop tasks/targets in [magefile.go](magefile.go) and [.vscode/tasks.json](.vscode/tasks.json).

## Contributing

Simply create an issue or a pull request.
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.7"
services:
builder:
container_name: builder
build: .
working_dir: /app
command: mage -v all
volumes:
- $PWD:/app

7 changes: 7 additions & 0 deletions foo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Package library has a dummy function covered by a unit test.
package library

// Foo returns "Bar".
func Foo() string {
return "Bar"
}
14 changes: 14 additions & 0 deletions foo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package library_test

import (
"testing"

. "github.com/golang-templates/library"
)

func TestFoo(t *testing.T) {
want := "Bar"
if got := Foo(); got != want {
t.Errorf("Foo() = %v, want %v", got, want)
}
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/golang-templates/library

go 1.14

require github.com/magefile/mage v1.9.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/magefile/mage v1.9.0 h1:t3AU2wNwehMCW97vuqQLtw6puppWXHO+O2MHo5a50XE=
github.com/magefile/mage v1.9.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
28 changes: 28 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//+build mage

package main

import (
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
)

// All full build: build, lint, test.
func All() {
mg.SerialDeps(Build, Lint, Test)
}

// Build go build.
func Build() error {
return sh.RunV("go", "build", "./...")
}

// Lint golangci-lint.
func Lint() error {
return sh.RunV("golangci-lint", "run")
}

// Test go test with race detector and code covarage.
func Test() error {
return sh.RunV("go", "test", "-race", "-covermode=atomic")
}

0 comments on commit d6e014b

Please sign in to comment.