Migrate to Go 1.18 (#45)

* Migrate to Go 1.18 and add linters
This commit is contained in:
Jonas Plum
2022-03-20 03:17:18 +01:00
committed by GitHub
parent 03a4806d45
commit 2bad1f5f28
88 changed files with 1430 additions and 868 deletions

View File

@@ -50,7 +50,7 @@ func New(c *Config) (*Bus, error) {
return &Bus{config: c, client: client}, err
}
func (b *Bus) jsonPublish(msg interface{}, channel, key string) error {
func (b *Bus) jsonPublish(msg any, channel, key string) error {
payload, err := json.Marshal(msg)
if err != nil {
return err
@@ -65,5 +65,6 @@ func (b *Bus) safeSubscribe(key, channel string, handler func(c *emitter.Client,
log.Printf("Recovered %s in channel %s\n", r, channel)
}
}()
return b.client.Subscribe(key, channel, handler)
}

View File

@@ -35,6 +35,7 @@ func (b *Bus) SubscribeDatabaseUpdate(f func(msg *DatabaseUpdateMsg)) error {
var msg DatabaseUpdateMsg
if err := json.Unmarshal(m.Payload(), &msg); err != nil {
log.Println(err)
return
}
go f(&msg)

View File

@@ -18,7 +18,7 @@ type JobMsg struct {
Message *model.Message `json:"message"`
}
func (b *Bus) PublishJob(id, automation string, payload interface{}, context *model.Context, origin *model.Origin) error {
func (b *Bus) PublishJob(id, automation string, payload any, context *model.Context, origin *model.Origin) error {
return b.jsonPublish(&JobMsg{
ID: id,
Automation: automation,
@@ -35,6 +35,7 @@ func (b *Bus) SubscribeJob(f func(msg *JobMsg)) error {
var msg JobMsg
if err := json.Unmarshal(m.Payload(), &msg); err != nil {
log.Println(err)
return
}
go f(&msg)

View File

@@ -29,6 +29,7 @@ func (b *Bus) SubscribeRequest(f func(msg *RequestMsg)) error {
msg := &RequestMsg{}
if err := json.Unmarshal(m.Payload(), msg); err != nil {
log.Println(err)
return
}
go f(msg)

View File

@@ -12,12 +12,12 @@ import (
const channelResult = "result"
type ResultMsg struct {
Automation string `json:"automation"`
Data map[string]interface{} `json:"data,omitempty"`
Target *model.Origin `json:"target"`
Automation string `json:"automation"`
Data map[string]any `json:"data,omitempty"`
Target *model.Origin `json:"target"`
}
func (b *Bus) PublishResult(automation string, data map[string]interface{}, target *model.Origin) error {
func (b *Bus) PublishResult(automation string, data map[string]any, target *model.Origin) error {
return b.jsonPublish(&ResultMsg{Automation: automation, Data: data, Target: target}, channelResult, b.config.resultBusKey)
}
@@ -26,6 +26,7 @@ func (b *Bus) SubscribeResult(f func(msg *ResultMsg)) error {
msg := &ResultMsg{}
if err := json.Unmarshal(m.Payload(), msg); err != nil {
log.Println(err)
return
}
go f(msg)