Skip to content

Commit

Permalink
chore: Update Go to v1.20 (#1775)
Browse files Browse the repository at this point in the history
* Update Go to v1.20
* Use `strings.CutPrefix` instead of `strings.TrimPrefix` where appropriate

Signed-off-by: Andrew Haines <haines@cerbos.dev>
  • Loading branch information
haines committed Aug 30, 2023
1 parent 7bfa52a commit cc2d95d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Submitting pull requests
- Run the pre-commit checks that are appropriate for the kind of change. (See below for details.)
- Submit your pull request.
- We require all pull requests to follow the [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) format.
- Use [closing keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) to link the PR to the original issue.
- Use [closing keywords](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) to link the PR to the original issue.
- At least one approval from a maintainer is required to merge the pull request.


Expand All @@ -33,7 +33,7 @@ Submitting pull requests
- Add tests to cover the functionality you are adding or modifying.
- Add new documentation or update existing content to ensure that the documentation stays consistent with the change you are introducing. See [below](#submitting-pull-requests-for-documentation-changes) for tips on writing documentation.
- Avoid introducing new dependencies if possible. All dependencies must have an appropriate open source licence (Apache-2.0, BSD, MIT).
- Make sure your code is `gofmt`ed. Run `make lint` and fix any warnings produced by the linter.
- Make sure your code is `gofmt`ed. Run `make lint` and fix any warnings produced by the linter.
- Sign-off your commits to provide a [DCO](https://developercertificate.org). You can do this by adding the `-s` flag to your `git commit` command.
```sh
git commit -s -m 'bug: Fix for bug X'
Expand All @@ -53,15 +53,15 @@ Submitting pull requests
Developing Cerbos
-----------------

Cerbos is developed using the [Go programming language](https://golang.org). We currently require Go 1.19.x for development.
Cerbos is developed using the [Go programming language](https://golang.org). We currently require Go 1.20.x for development.

The `Makefile` automatically installs required build tools using the versions defined in `tools/go.mod`. Run `make clean-tools` to clear the cache and force the installation of new versions.

Useful `make` targets:

- `make build`: Compile, test and build the Cerbos binaries and container. Binaries will be output to the `dist` directory. The container name would be `ghcr.io/cerbos/cerbos:<VERSION>-prerelease`.
- `make pre-commit`: Run tests, lint, and generate code and documentation. Run this before submitting a PR to make sure your code is ready to submit.
- `make dev-server`: Start a Cerbos server
- `make dev-server`: Start a Cerbos server
- `make docs`: Generate docs and preview in browser.


Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ confdocs:

.PHONY: deps
deps:
@ go mod tidy -compat=1.19
@ go mod tidy -compat=1.20

.PHONY: test-all
test-all: test-race test-integration
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cerbos/cerbos

go 1.19
go 1.20

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.2
Expand Down
2 changes: 1 addition & 1 deletion hack/tools/protoc-gen-jsonschema/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cerbos/cerbos/hack/tools/protoc-gen-jsonschema

go 1.19
go 1.20

require (
github.com/envoyproxy/protoc-gen-validate v1.0.2
Expand Down
2 changes: 1 addition & 1 deletion hack/tools/testsplit/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cerbos/cerbos/hack/tools/testsplit

go 1.19
go 1.20

require (
github.com/alecthomas/kong v0.8.0
Expand Down
7 changes: 3 additions & 4 deletions internal/storage/git/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,11 @@ func (s *Store) normalizePath(path string) (string, util.IndexedFileType) {
}

if s.subDir != "." {
relativePath := strings.TrimPrefix(path, s.subDir+"/")
if path == relativePath { // not in policies directory
var ok bool
path, ok = strings.CutPrefix(path, s.subDir+"/")
if !ok { // not in policies directory
return path, util.FileTypeNotIndexed
}

path = relativePath
}

fileType := util.FileType(path)
Expand Down
8 changes: 4 additions & 4 deletions internal/util/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ func FileType(path string) IndexedFileType {
// and a flag to indicate whether the path was actually contained in that directory.
// The path must be "/"-separated and relative to the root policies directory.
func RelativeSchemaPath(path string) (string, bool) {
schemaPath := strings.TrimPrefix(path, SchemasDirectory+"/")
if schemaPath == path {
return "", false
schemaPath, ok := strings.CutPrefix(path, SchemasDirectory+"/")
if !ok {
schemaPath = ""
}

return schemaPath, true
return schemaPath, ok
}
2 changes: 1 addition & 1 deletion tools/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cerbos/cerbos/tools

go 1.19
go 1.20

require (
github.com/bojand/ghz v0.117.0
Expand Down

0 comments on commit cc2d95d

Please sign in to comment.