Skip to content

Commit

Permalink
use go1.18 minimum
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Aug 5, 2022
1 parent d9250bb commit 6265a57
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 194 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,32 @@ jobs:

strategy:
matrix:
go: [ 1.17, 1.18 ]
go: [ 1.18, 1.19 ]

steps:
- name: Checkout code
uses: actions/checkout@v1
with:
path: src/github.com/nats-io/jsm.go
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: ${{ matrix.go }}

- name: Install deps
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
export GOPATH="$RUNNER_WORKSPACE"
go get -v -u honnef.co/go/tools/cmd/staticcheck
go get -v -u github.com/client9/misspell/cmd/misspell
go version
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/client9/misspell/cmd/misspell@latest
- name: Lint
shell: bash --noprofile --norc -x -eo pipefail {0}
run: |
export GOPATH="$RUNNER_WORKSPACE"
PATH=$PATH:$GOPATH/bin
$(exit $(go fmt $(go list ./...) | wc -l))
find . -type f -name "*.go" | grep -v "/vendor/" | xargs misspell -error -locale US
find . -type f -name "*.go" | xargs misspell -error -locale US
staticcheck -f stylish $(go list ./...)
go vet ./...
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ JetStream will produce metrics about message Acknowledgments, API audits and mor
nc.Subscribe("$JS.EVENT.ADVISORY.>", func(m *nats.Msg){
kind, msg, _ := api.ParseMessage(m.Data)
log.Printf("Received message of type %s", kind) // io.nats.jetstream.advisory.v1.api_audit

switch e := event.(type){
case advisory.JetStreamAPIAuditV1:
fmt.Printf("Audit event on subject %s from %s\n", e.Subject, e.Client.Name)
fmt.Printf("Audit event on subject %s from %s\n", e.Subject, e.Client.Name)
}
})
```
Expand Down Expand Up @@ -141,7 +141,7 @@ provide better errors.
```go
type SchemaValidator struct{}

func (v SchemaValidator) ValidateStruct(data interface{}, schemaType string) (ok bool, errs []string) {
func (v SchemaValidator) ValidateStruct(data any, schemaType string) (ok bool, errs []string) {
s, err := api.Schema(schemaType)
if err != nil {
return false, []string{"unknown schema type %s", schemaType}
Expand Down
6 changes: 4 additions & 2 deletions api/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"time"

"github.com/dustin/go-humanize"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

var (
Expand Down Expand Up @@ -135,7 +137,7 @@ type stringer interface {
}

func compileTemplate(schema string, body string) (*template.Template, error) {
return template.New(schema).Funcs(map[string]interface{}{
return template.New(schema).Funcs(map[string]any{
"ShortTime": func(v time.Time) string { return v.Format("15:04:05") },
"NanoTime": func(v time.Time) string { return v.Format("15:04:05.000") },
"IBytes": func(v int64) string { return humanize.IBytes(uint64(v)) },
Expand All @@ -144,7 +146,7 @@ func compileTemplate(schema string, body string) (*template.Template, error) {
"HostPort": func(h string, p int) string { return net.JoinHostPort(h, strconv.Itoa(p)) },
"LeftPad": func(indent int, v string) string { return leftPad(v, indent) },
"ToString": func(v stringer) string { return v.String() },
"TitleString": func(v string) string { return strings.Title(v) },
"TitleString": func(v string) string { return cases.Title(language.AmericanEnglish).String(v) },
"JoinStrings": func(v []string) string { return strings.Join(v, ",") },
}).Parse(body)
}
Expand Down
2 changes: 1 addition & 1 deletion api/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Example() {
}
fmt.Printf("Type Schema URL: %s (%s)\n", address, uri.Host)

// parses an event into it a type if supported else map[string]interface{}
// parses an event into it a type if supported else map[string]any
schema, event, err := ParseMessage([]byte(receivedEvent))
if err != nil {
panic(err.Error())
Expand Down
6 changes: 3 additions & 3 deletions api/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ import (
scfs "github.com/nats-io/jsm.go/schemas"
)
var schemaTypes = map[string]func() interface{}{
var schemaTypes = map[string]func() any {
{{- range . }}
{{- if .St }}
"{{ .T }}": func() interface{} { return &{{ .St }}{} },
"{{ .T }}": func() any { return &{{ .St }}{} },
{{- end }}
{{- end }}
"io.nats.unknown_message": func() interface{} { return &UnknownMessage{} },
"io.nats.unknown_message": func() any { return &UnknownMessage{} },
}
{{- range . }}
Expand Down
8 changes: 4 additions & 4 deletions api/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
var SchemasRepo = "https://raw.githubusercontent.com/nats-io/jsm.go/master/schemas"

// UnknownMessage is a type returned when parsing an unknown type of event
type UnknownMessage = map[string]interface{}
type UnknownMessage = map[string]any

// Event is a generic NATS Event capable of being converted to CloudEvents format
type Event interface {
Expand All @@ -32,7 +32,7 @@ type Event interface {

// StructValidator is used to validate API structures
type StructValidator interface {
ValidateStruct(data interface{}, schemaType string) (ok bool, errs []string)
ValidateStruct(data any, schemaType string) (ok bool, errs []string)
}

// RenderFormat indicates the format to render templates in
Expand Down Expand Up @@ -156,7 +156,7 @@ func Schema(schemaType string) (schema []byte, err error) {
}

// NewMessage creates a new instance of the structure matching schema. When unknown creates a UnknownMessage
func NewMessage(schemaType string) (interface{}, bool) {
func NewMessage(schemaType string) (any, bool) {
gf, ok := schemaTypes[schemaType]
if !ok {
gf = schemaTypes["io.nats.unknown_message"]
Expand All @@ -167,7 +167,7 @@ func NewMessage(schemaType string) (interface{}, bool) {

// ParseMessage parses a typed message m and returns event as for example *api.ConsumerAckMetric, all unknown
// event schemas will be of type *UnknownMessage
func ParseMessage(m []byte) (schemaType string, msg interface{}, err error) {
func ParseMessage(m []byte) (schemaType string, msg any, err error) {
schemaType, err = SchemaTypeForMessage(m)
if err != nil {
return "", nil, err
Expand Down
Loading

0 comments on commit 6265a57

Please sign in to comment.