A broadly featured Go helper library with standalone packages
Mantis
Mantis is a collection of helper libraries written in order to reduce
the need to code common patterns and functionality. Subpackages are developed, when possible,
to have zero side effects on the parent application - helper functions are (or in some cases will be)
written in such a manner that they accept, act on, and return data.
Mantis, much like its namesake (Jet's Go-Mantis library), is the
"standard library" for Sphire's Golang codebase, used heavily in projects like Sphire Core and Sphire Codex.
Warning
Mantis is NOT production ready code - use at your own risk.
Usage
Running go get github.com/sphireinc/mantis
will fetch the mantis project within your Go project.
Imports work at a package level. If you'd like to use the date package, please do:
package main
import (
mantisDate `github.com/sphireinc/mantis/date`
)
func main(){
datem := mantisDate.CurrentTime() // return type: mantisDate.Date
fmt.Println(datem.String())
}
$ go run main.go
{
"year": 2009,
"month": 11,
"day": 10,
"hour": 23,
"minute": 0,
"second": 0,
"nanosecond": 0,
"unix": 1257894000,
"week_day": 2,
"year_day": 314
}
Tests
Each package can be tested independently via go test
, or all packages can be tested from
the root via go test ./...
Local Development
You should ideally install these packages:
go install golang.org/x/lint/golint@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest
go install golang.org/x/tools/cmd/goimports@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
Then you should run these commands, ideally as a pre-commit check:
go fmt
go vet
golint package_name
staticcheck
goimports -v -e -w package_name
Go Cyclo
Mantis makes use of gocyclo
in order to ensure cyclomatic complexity remains low. All functions should
standardize below a 10, following Tom McCabes categorizations from his "Software Quality Metrics
to Identify Risk" presentation for the Department of Homeland Security:
- 1 - 10 Simple procedure, little risk
- 11 - 20 More complex, moderate risk
- 21 - 50 Complex, high risk
- > 50 Untestable code, very high risk
GoLoC
Using https://github.com/hhatto/gocloc
Language |
files |
blank |
comment |
code |
Go |
615 |
20,351 |
22,051 |
105,753 |
Markdown |
61 |
1,610 |
0 |
6,389 |
Plain Text |
7 |
160 |
0 |
930 |
Makefile |
4 |
128 |
36 |
476 |
XML |
6 |
0 |
0 |
299 |
YAML |
18 |
49 |
15 |
269 |
JSON |
5 |
0 |
0 |
199 |
Assembly |
1 |
39 |
42 |
134 |
Bourne Shell |
3 |
12 |
4 |
74 |
TOML |
3 |
29 |
1 |
73 |
BASH |
2 |
4 |
7 |
33 |
TOTAL |
725 |
22,382 |
22,156 |
114,629 |
Contributing
Please find our contribution guidelines within CONTRIBUTING.md
Thanks
Thanks to all below for their contributions, inspiration, or otherwise: