Skip to content

Commit 8a64554

Browse files
authored
Initial commit
0 parents  commit 8a64554

File tree

8 files changed

+214
-0
lines changed

8 files changed

+214
-0
lines changed

.github/workflows/go.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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: govulncheck
28+
uses: golang/govulncheck-action@v1
29+
with:
30+
go-version-input: 1.21
31+
go-package: ./...
32+
33+
- name: Test
34+
run: go test -v -coverprofile=coverage.txt -covermode=atomic ./...
35+
36+
- name: Codecov upload coverage
37+
shell: bash
38+
env:
39+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
40+
RUN_ID: ${{ github.run_id }}
41+
run: |
42+
# Replace `linux` below with the appropriate OS
43+
# Options are `alpine`, `linux`, `macos`, `windows`
44+
# You will need to setup the environment variables below in github
45+
# and the project in codecov.io: https://app.codecov.io/gh/${{ github.repository }}
46+
go test -v -coverprofile=coverage.txt -covermode=atomic ./...
47+
curl -Os https://uploader.codecov.io/latest/linux/codecov
48+
chmod +x codecov
49+
./codecov --verbose upload-process --fail-on-error -t $CODECOV_TOKEN -n 'service'-$RUN_ID -F service -f coverage.txt

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
19+
# `__debug_bin` Debug binary generated in VSCode when using the built-in debugger.
20+
**__debug_bin*
21+
*bin
22+
23+
# IDE
24+
.vscode/
25+
26+
# For local development and testing create `local` directories.
27+
local
28+
29+
# Output of the go coverage tool, specifically when used with LiteIDE
30+
*.out
31+
*.cov
32+
33+
# Log files and common data formats.
34+
*.log
35+
*.Log
36+
*.LOG
37+
*.csv
38+
*.tsv
39+
*.dat
40+
*.json
41+
*.xlsx
42+
*.xls
43+
*.zip
44+
*.gz
45+
*.tar
46+
47+
# If running a python script.
48+
*/__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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
[![sourcegraph](https://sourcegraph.com/github.com/soypat/go-module-template/-/badge.svg)](https://sourcegraph.com/github.com/soypat/go-module-template?badge)
7+
<!--
8+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9+
10+
[![stability-experimental](https://img.shields.io/badge/stability-experimental-orange.svg)](https://github.com/emersion/stability-badges#experimental)
11+
12+
See https://github.com/emersion/stability-badges#unstable for more stability badges.
13+
-->
14+
15+
Go module template with instructions on how to make your code importable and setting up codecov CI.
16+
17+
How to install package with newer versions of Go (+1.16):
18+
```sh
19+
go mod download github.com/soypat/go-module-template@latest
20+
```
21+
22+
23+
## First steps
24+
25+
0. Replace LICENSE with your desired license. BSD 3 clause is included by default.
26+
27+
1. Fix `go.mod` file by replacing `github.com/YOURUSER/YOURREPONAME` with your corresponding project repository link.
28+
29+
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`.
30+
31+
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":
32+
- [`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.
33+
- Similarily [`sdf`](https://github.com/soypat/sdf) also does the same with defining interfaces top level.
34+
35+
## Setting up codecov CI
36+
This instructive will allow for tests to run on pull requests and pushes to your repository.
37+
38+
1. Create an account on [codecov.io](https://app.codecov.io/)
39+
40+
2. Setup repository on codecov and obtain the CODECOV_TOKEN token, which is a string of base64 characters.
41+
42+
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".
43+
44+

cmd/hello-world/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import (
4+
"os"
5+
)
6+
7+
func main() {
8+
os.Stdout.WriteString("Hello world!\n")
9+
}

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)