Skip to content

Commit

Permalink
(misc) update to go 1.18
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Dec 18, 2022
1 parent 3d1ad7f commit 31a0f0f
Show file tree
Hide file tree
Showing 29 changed files with 93 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
strategy:
matrix:
go: [ 1.17, 1.18 ]
go: [ 1.18, 1.19 ]

runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ client, _ := asyncjobs.NewClient(
asyncjobs.RetryBackoffPolicy(asyncjobs.RetryLinearTenMinutes))

router := asyncjobs.NewTaskRouter()
router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (interface{}, error) {
router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (any, error) {
log.Printf("Processing task %s", task.ID)

// do work here using task.Payload
Expand Down
2 changes: 1 addition & 1 deletion ajc/task_cron_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (c *taskCronCommand) addAction(_ *fisk.ParseContext) error {
opts = append(opts, aj.TaskMaxTries(c.maxtries))
}

var payload interface{}
var payload any
if c.payload != "" {
payload = c.payload
}
Expand Down
2 changes: 1 addition & 1 deletion ajc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func humanizeDuration(d time.Duration) string {
return fmt.Sprintf("%.2fs", d.Seconds())
}

func dumpJSON(d interface{}) {
func dumpJSON(d any) {
j, err := json.MarshalIndent(d, "", " ")
if err != nil {
panic(fmt.Sprintf("could not JSON render: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (c *Client) saveOrDiscardTaskIfDesired(ctx context.Context, t *Task) error
return c.storage.DeleteTaskByID(t.ID)
}

func (c *Client) setTaskSuccess(ctx context.Context, t *Task, payload interface{}) error {
func (c *Client) setTaskSuccess(ctx context.Context, t *Task, payload any) error {
t.LastTriedAt = nowPointer()
t.State = TaskStateCompleted
t.LastErr = ""
Expand Down
6 changes: 3 additions & 3 deletions client_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"
)

func newEmail(to, subject, body string) map[string]interface{} {
return map[string]interface{}{
func newEmail(to, subject, body string) map[string]any {
return map[string]any{
"to": to,
"subject": subject,
"body": body,
Expand Down Expand Up @@ -71,7 +71,7 @@ func ExampleClient_consumer() {
panicIfErr(err)

router := NewTaskRouter()
err = router.HandleFunc("email:send", func(_ context.Context, _ Logger, t *Task) (interface{}, error) {
err = router.HandleFunc("email:send", func(_ context.Context, _ Logger, t *Task) (any, error) {
log.Printf("Processing task: %s", t.ID)

// handle task.Payload which is a JSON encoded email
Expand Down
7 changes: 3 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"sync"
Expand All @@ -29,7 +28,7 @@ func TestAsyncJobs(t *testing.T) {
}

func withJetStream(cb func(nc *nats.Conn, mgr *jsm.Manager)) {
d, err := ioutil.TempDir("", "jstest")
d, err := os.MkdirTemp("", "jstest")
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(d)

Expand Down Expand Up @@ -152,7 +151,7 @@ var _ = Describe("Client", func() {
handled := int32(0)

router := NewTaskRouter()
router.HandleFunc("test", func(ctx context.Context, log Logger, t *Task) (interface{}, error) {
router.HandleFunc("test", func(ctx context.Context, log Logger, t *Task) (any, error) {
if t.Tries > 1 {
log.Infof("Try %d for task %s", t.Tries, t.ID)
}
Expand Down Expand Up @@ -212,7 +211,7 @@ var _ = Describe("Client", func() {
var tries []time.Time

router := NewTaskRouter()
router.HandleFunc("ginkgo", func(ctx context.Context, log Logger, t *Task) (interface{}, error) {
router.HandleFunc("ginkgo", func(ctx context.Context, log Logger, t *Task) (any, error) {
tries = append(tries, time.Now())

log.Infof("Trying task %s on try %d\n", t.ID, t.Tries)
Expand Down
2 changes: 1 addition & 1 deletion docs/content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ client, _ := asyncjobs.NewClient(
asyncjobs.RetryBackoffPolicy(asyncjobs.RetryLinearTenMinutes))

router := asyncjobs.NewTaskRouter()
router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (interface{}, error) {
router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (any, error) {
log.Printf("Processing task %s", task.ID)

// do work here using task.Payload
Expand Down
4 changes: 2 additions & 2 deletions docs/content/overview/golang-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Any number of producers can create tasks from any number of different processes.
First we have a simplistic helper to create a map that describes an email:

```go
func newEmail(to, subject, body string) interface{} {
func newEmail(to, subject, body string) any {
return map[string]string{"to": to, "subject": subject, "body": body}
}
```
Expand Down Expand Up @@ -105,7 +105,7 @@ client, err := asyncjobs.NewClient(
panicIfErr(err)

router := asyncjobs.NewTaskRouter()
err = router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (interface{}, error) {
err = router.Handler("email:new", func(ctx context.Context, log asyncjobs.Logger, task *asyncjobs.Task) (any, error) {
log.Printf("Processing task %s", task.ID)

// do work here using task.Payload
Expand Down
2 changes: 1 addition & 1 deletion docs/content/overview/handlers-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
aj "github.com/choria-io/asyncjobs"
)

func AsyncJobHandler(ctx context.Context, log aj.Logger, task *aj.Task) (interface{}, error) {
func AsyncJobHandler(ctx context.Context, log aj.Logger, task *aj.Task) (any, error) {
// process your email
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/routing-concurrency-retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Below is a handler that sends an email, the task Payload is a serialized object
The Task handler then is a single-purpose piece of code capable of handling 1 type of Task.

```go
func emailNewHandler(ctx context.Context, log asycjobs.Logger, task *asyncjobs.Task) (interface{}, error) {
func emailNewHandler(ctx context.Context, log asycjobs.Logger, task *asyncjobs.Task) (any, error) {
// Parse the task payload into an email
email, err := parseEmail(task.Payload)
if err != nil { return nil, err }
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/terminology.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Connects to JetStream and manages the enqueueing and routing of tasks.

## Handler

Handlers are functions that can process a task with the signature `func(context.Context, *asyncjobs.Task) (interface{}, error)`.
Handlers are functions that can process a task with the signature `func(context.Context, *asyncjobs.Task) (any, error)`.

## Router

Expand Down
2 changes: 1 addition & 1 deletion election/election.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func NewElection(name string, key string, bucket nats.KeyValue, opts ...Option)
return e, nil
}

func (e *election) debugf(format string, a ...interface{}) {
func (e *election) debugf(format string, a ...any) {
if e.opts.debug == nil {
return
}
Expand Down
7 changes: 3 additions & 4 deletions election/election_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package election
import (
"context"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"
Expand All @@ -31,7 +30,7 @@ var _ = Describe("Leader Election", func() {
js nats.KeyValueManager
kv nats.KeyValue
err error
debugger func(f string, a ...interface{})
debugger func(f string, a ...any)
)

BeforeEach(func() {
Expand All @@ -45,7 +44,7 @@ var _ = Describe("Leader Election", func() {
TTL: 750 * time.Millisecond,
})
Expect(err).ToNot(HaveOccurred())
debugger = func(f string, a ...interface{}) {
debugger = func(f string, a ...any) {
fmt.Fprintf(GinkgoWriter, fmt.Sprintf("%s\n", f), a...)
}
})
Expand Down Expand Up @@ -208,7 +207,7 @@ var _ = Describe("Leader Election", func() {
func startJSServer(t GinkgoTInterface) (*server.Server, *nats.Conn) {
t.Helper()

d, err := ioutil.TempDir("", "jstest")
d, err := os.MkdirTemp("", "jstest")
if err != nil {
t.Fatalf("temp dir could not be made: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions election/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type options struct {
lostCb func()
campaignCb func(s State)
bo Backoff
debug func(format string, a ...interface{})
debug func(format string, a ...any)
}

// WithBackoff will use the provided Backoff timer source to decrease campaign intervals over time
Expand All @@ -47,6 +47,6 @@ func OnCampaign(cb func(s State)) Option {
}

// WithDebug sets a function to do debug logging with
func WithDebug(cb func(format string, a ...interface{})) Option {
func WithDebug(cb func(format string, a ...any)) Option {
return func(o *options) { o.debug = cb }
}
2 changes: 1 addition & 1 deletion generators/godocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (g *GoContainer) RenderToDirectory(target string) error {
}
}

funcs := map[string]interface{}{
funcs := map[string]any{
"RetryNamesList": func() string {
return strings.Join(aj.RetryPolicyNames(), ", ")
},
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.15.13 // indirect
github.com/kr/pretty v0.1.0 // indirect
Expand All @@ -45,5 +47,6 @@ require (
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.4.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/choria-io/fisk v0.2.1 h1:Ful0jPqo5LvDMnkQfTnRWl29NGA2TmL0Qj6UMyQcHyU=
github.com/choria-io/fisk v0.2.1/go.mod h1:S+NQ8qIofXvjz4zT4t69xRudzMYNfOG3uC0lOzGNjHA=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -17,6 +20,8 @@ github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
Expand All @@ -25,8 +30,11 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/klauspost/compress v1.15.13 h1:NFn1Wr8cfnenSJSA46lLq4wHCcBzKTSjnBIexDMMOV0=
Expand Down Expand Up @@ -83,6 +91,7 @@ github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
Expand All @@ -97,6 +106,7 @@ golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -113,13 +123,16 @@ golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.4.0 h1:7mTAgkunk3fr4GAloyyCasadO6h9zSsQZbwvcaIciV4=
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const (
)

// ParseEventJSON parses event bytes returning the parsed Event and its event type
func ParseEventJSON(event []byte) (interface{}, string, error) {
func ParseEventJSON(event []byte) (any, string, error) {
var base BaseEvent
err := json.Unmarshal(event, &base)
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ import (

// Logger is a pluggable logger interface
type Logger interface {
Debugf(format string, v ...interface{})
Infof(format string, v ...interface{})
Warnf(format string, v ...interface{})
Errorf(format string, v ...interface{})
Debugf(format string, v ...any)
Infof(format string, v ...any)
Warnf(format string, v ...any)
Errorf(format string, v ...any)
}

// Default console logger
type defaultLogger struct{}

func (l *defaultLogger) Infof(format string, v ...interface{}) {
func (l *defaultLogger) Infof(format string, v ...any) {
log.Printf(format, v...)
}

func (l *defaultLogger) Warnf(format string, v ...interface{}) {
func (l *defaultLogger) Warnf(format string, v ...any) {
log.Printf(format, v...)
}

func (l *defaultLogger) Errorf(format string, v ...interface{}) {
func (l *defaultLogger) Errorf(format string, v ...any) {
log.Printf(format, v...)
}

func (l *defaultLogger) Debugf(format string, v ...interface{}) {
func (l *defaultLogger) Debugf(format string, v ...any) {
log.Printf(format, v...)
}

// Logger placeholder
type noopLogger struct{}

func (l *noopLogger) Infof(format string, v ...interface{}) {}
func (l *noopLogger) Warnf(format string, v ...interface{}) {}
func (l *noopLogger) Errorf(format string, v ...interface{}) {}
func (l *noopLogger) Debugf(format string, v ...interface{}) {}
func (l *noopLogger) Infof(format string, v ...any) {}
func (l *noopLogger) Warnf(format string, v ...any) {}
func (l *noopLogger) Errorf(format string, v ...any) {}
func (l *noopLogger) Debugf(format string, v ...any) {}
6 changes: 3 additions & 3 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type entryHandler struct {
}

// HandlerFunc handles a single task, the response bytes will be stored in the original task
type HandlerFunc func(ctx context.Context, log Logger, t *Task) (interface{}, error)
type HandlerFunc func(ctx context.Context, log Logger, t *Task) (any, error)

// Mux routes messages
//
Expand All @@ -44,7 +44,7 @@ func NewTaskRouter() *Mux {
}
}

func notFoundHandler(_ context.Context, _ Logger, t *Task) (interface{}, error) {
func notFoundHandler(_ context.Context, _ Logger, t *Task) (any, error) {
return nil, fmt.Errorf("%w %q", ErrNoHandlerForTaskType, t.Type)
}

Expand Down Expand Up @@ -98,7 +98,7 @@ func (m *Mux) RequestReply(taskType string, client *Client) error {
// The task will be passed in JSON format on STDIN, any STDOUT/STDERR output will become the task
// result. Any non 0 exit code will be treated as a task failure.
func (m *Mux) ExternalProcess(taskType string, command string) error {
return m.HandleFunc(taskType, func(ctx context.Context, log Logger, task *Task) (interface{}, error) {
return m.HandleFunc(taskType, func(ctx context.Context, log Logger, task *Task) (any, error) {
stat, err := os.Stat(command)
if err != nil || stat.IsDir() {
return nil, ErrExternalCommandNotFound
Expand Down
Loading

0 comments on commit 31a0f0f

Please sign in to comment.