Skip to content

Commit a1e281c

Browse files
authored
Initial commit
0 parents  commit a1e281c

File tree

7 files changed

+202
-0
lines changed

7 files changed

+202
-0
lines changed

.github/workflows/go.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Go
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v3
21+
with:
22+
go-version: 1.21
23+
24+
- name: Build
25+
run: go build -v ./...
26+
27+
- name: Test
28+
run: go test -v -coverprofile=coverage.txt -covermode=atomic ./...
29+
30+
- name: govulncheck
31+
uses: golang/govulncheck-action@v1
32+
with:
33+
go-version-input: 1.21
34+
go-package: ./...
35+
36+
- shell: bash
37+
env:
38+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
39+
run: |
40+
# Replace `linux` below with the appropriate OS
41+
# Options are `alpine`, `linux`, `macos`, `windows`
42+
# You will need to setup the environment variables below in github
43+
# and the project in codecov.io
44+
go test -v -coverprofile=coverage.txt -covermode=atomic ./...
45+
curl -Os https://uploader.codecov.io/latest/linux/codecov
46+
chmod +x codecov
47+
CODECOV_TOKEN=$CODECOV_TOKEN ./codecov

.gitignore

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Go workspaces.
2+
go.work
3+
go.work.sum
4+
# Test binary, built with `go test -c`
5+
*.test
6+
# Dependency directories after running `go mod vendor`
7+
vendor/
8+
9+
# Binaries for programs and plugins
10+
*.elf
11+
*.uf2
12+
*.exe
13+
*.exe~
14+
*.dll
15+
*.so
16+
*.dylib
17+
*.hex
18+
# `__debug_bin` Debug binary generated in VSCode when using the built-in debugger.
19+
*bin
20+
21+
# IDE
22+
.vscode/
23+
24+
# For local development and testing create `local` directories.
25+
local
26+
27+
# Output of the go coverage tool, specifically when used with LiteIDE
28+
*.out
29+
*.cov
30+
31+
# Log files and common data formats.
32+
*.log
33+
*.Log
34+
*.LOG
35+
*.csv
36+
*.tsv
37+
*.dat
38+
*.json
39+
*.xlsx
40+
*.xls
41+
*.zip
42+
*.gz
43+
*.tar
44+
45+
# If running a python script.
46+
*/__pycache__/*

LICENSE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2023, Patricio Whittingslow
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# go-module-template
2+
[![go.dev reference](https://pkg.go.dev/badge/github.com/soypat/go-module-template)](https://pkg.go.dev/github.com/soypat/go-module-template)
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/soypat/go-module-template)](https://goreportcard.com/report/github.com/soypat/go-module-template)
4+
[![codecov](https://codecov.io/gh/soypat/go-module-template/branch/main/graph/badge.svg)](https://codecov.io/gh/soypat/go-module-template)
5+
[![Go](https://github.com/soypat/go-module-template/actions/workflows/go.yml/badge.svg)](https://github.com/soypat/go-module-template/actions/workflows/go.yml)
6+
[![stability-frozen](https://img.shields.io/badge/stability-frozen-blue.svg)](https://github.com/emersion/stability-badges#frozen)
7+
[![sourcegraph](https://sourcegraph.com/github.com/soypat/go-module-template/-/badge.svg)](https://sourcegraph.com/github.com/soypat/go-module-template?badge)
8+
<!--
9+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10+
11+
[![stability-experimental](https://img.shields.io/badge/stability-experimental-orange.svg)](https://github.com/emersion/stability-badges#experimental)
12+
13+
See https://github.com/emersion/stability-badges#unstable for more stability badges.
14+
-->
15+
16+
Go module template with instructions on how to make your code importable and setting up codecov CI.
17+
18+
How to install package with newer versions of Go (+1.16):
19+
```sh
20+
go mod download github.com/soypat/go-module-template@latest
21+
```
22+
23+
24+
## First steps
25+
26+
0. Replace LICENSE with your desired license. BSD 3 clause is included by default.
27+
28+
1. Fix `go.mod` file by replacing `github.com/YOURUSER/YOURREPONAME` with your corresponding project repository link.
29+
30+
2. Replace `soypat/go-module-template` in the badge URLs. Make sure you've replaced all of them by performing text search in the readme for `soypat` and `template`.
31+
32+
3. Rename `module.go` and `module_test.go` to fit your own repository needs. Below are some exemplary modules that abide by what's generally considered "good practices":
33+
- [`mu8` minimal machine learning library](https://github.com/soypat/mu8). Note how most interfaces and interface algorithms are defined at the root package level and how the concrete implementations live in the subdirectories.
34+
- Similarily [`sdf`](https://github.com/soypat/sdf) also does the same with defining interfaces top level.
35+
36+
## Setting up codecov CI
37+
This instructive will allow for tests to run on pull requests and pushes to your repository.
38+
39+
1. Create an account on [codecov.io](https://app.codecov.io/)
40+
41+
2. Setup repository on codecov and obtain the CODECOV_TOKEN token, which is a string of base64 characters.
42+
43+
3. Open up the github repository for this project and go to `Settings -> Secrets and variables -> Actions`. Once there create a New Repository Secret. Name it `CODECOV_TOKEN` and copy paste the token obtained in the previous step in the `secret` input box. Click "Add secret".
44+
45+

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/YOURUSER/YOURREPONAME
2+
3+
go 1.20

module.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// package gomoduletemplate is a template repository
2+
// for creating new Go modules with basic CI instrumentation.
3+
package gomoduletemplate
4+
5+
// Fibonacci returns the nth number in the Fibonacci sequence.
6+
func Fibonacci(n int) int {
7+
a, b := 0, 1
8+
for i := 0; i < n; i++ {
9+
a, b = b, a+b
10+
}
11+
return a
12+
}

module_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package gomoduletemplate_test
2+
3+
import (
4+
"testing"
5+
6+
gomoduletemplate "github.com/YOURUSER/YOURREPONAME"
7+
)
8+
9+
func TestWorkingGoInstall(t *testing.T) {
10+
t.Log("Your go installation works!")
11+
}
12+
13+
func TestFibonacci(t *testing.T) {
14+
var sequence = []int{0, 1, 1, 2, 3, 5, 8, 13, 21, 34}
15+
for nth, expected := range sequence {
16+
got := gomoduletemplate.Fibonacci(nth)
17+
if got != expected {
18+
t.Errorf("Fibonacci(%d) = %d, expected %d", nth, got, expected)
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)