-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from smyrman/patch
update to use go.mod and GitHubActions
- Loading branch information
Showing
10 changed files
with
149 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Go | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.17 | ||
id: go | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Go modules cache | ||
id: cache-go-module | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Setup Go build cache | ||
id: cache-go-build | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cache/go-build | ||
key: ${{ runner.os }}-gobuild-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-gobuild- | ||
- name: Download dependencies | ||
if: steps.cache-go-module.outputs.cache-hit != 'true' | ||
run: go mod download | ||
|
||
- name: Verify go modules up to date | ||
run: | | ||
set -ex | ||
go mod tidy | ||
[ -z "$(git diff -- go.{mod,sum})" ] # Check there are no changes! | ||
- name: Test | ||
run: go test -race ./... | ||
|
||
# Run golangci-lint in same job as tests as the golangci-lint task can not | ||
# resolve private dependencies. | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.50 | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
only-new-issues: false | ||
skip-cache: false | ||
skip-pkg-cache: true | ||
skip-build-cache: true | ||
args: --timeout=10m |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/smyrman/units | ||
|
||
go 1.17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// This code is generated by units-codegen; do not manualy edit this file. | ||
{{$self := .Self}}{{$name := .Name}} | ||
package {{.PkgName}} | ||
|
||
{{if .Import}}import ({{range .Import}} | ||
"{{.}}"{{end}} | ||
){{end}} | ||
|
||
// Units for {{.Name}} values. Always multiply with a unit when setting the initial value like you would for | ||
// time.Time. This prevents you from having to worry about the internal storage format. | ||
const ({{range .Units}} | ||
{{.Name}} {{$name}} = {{.Value}}{{end}} | ||
) | ||
{{range .Units}} | ||
// {{.NamePlural}} returns {{$self}} as a floating point number of {{.NamePlural|lower}}. | ||
func ({{$self}} {{$name}}) {{.NamePlural}}() float64 { | ||
return float64({{$self}} / {{.Name}}) | ||
} | ||
{{end}} | ||
// Abs returns the absolute value of {{.Self}} as a copy. | ||
func ({{.Self}} {{.Name}}) Abs() {{.Name}} { | ||
if {{.Self}} < 0 { | ||
return -{{.Self}} | ||
} | ||
return {{.Self}} | ||
} | ||
|
||
// Mul returns the product of {{.Self}} * x as a new {{.Name}}. | ||
func ({{.Self}} {{.Name}}) Mul(x float64) {{.Name}} { | ||
return {{.Self}} * {{.Name}}(x) | ||
} | ||
|
||
// Div returns the quotient of {{.Self}} / x as a new {{.Name}}. | ||
func ({{.Self}} {{.Name}}) Div(x float64) {{.Name}} { | ||
return {{.Self}} / {{.Name}}(x) | ||
} | ||
|
||
// Div{{.Name}} returns the quotient of {{.Self}} / x as a floating point number. | ||
func ({{.Self}} {{.Name}}) Div{{.Name}}(x {{.Name}}) float64 { | ||
return float64({{.Self}} / x) | ||
} | ||
{{if .DivDurationType}} | ||
// DivDuration returns the quotient of {{.Self}} / t as a {{.DivDurationType}}. | ||
func ({{.Self}} {{.Name}}) DivDuration(t time.Duration) {{.DivDurationType}} { | ||
return {{.DivDurationType}}(float64({{.Self}}) / float64(t)) | ||
} | ||
|
||
// Div{{.DivDurationType}} returns the quotient of {{.Self}} / x as a time.Duration. | ||
func ({{.Self}} {{.Name}}) Div{{.DivDurationType}}(x {{.DivDurationType}}) time.Duration { | ||
return time.Duration(float64({{.Self}}) / float64(x)) | ||
}{{end}} | ||
{{if .MulDurationType}} | ||
// MulDuration returns the product of {{.Self}} * t as a {{.MulDurationType}}. | ||
func ({{.Self}} {{.Name}}) MulDuration(t time.Duration) {{.MulDurationType}} { | ||
return {{.MulDurationType}}(float64({{.Self}}) * float64(t)) | ||
}{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters