From 2f48989b365788cae7b480d6cee70de5fb9d608d Mon Sep 17 00:00:00 2001 From: Christian Stewart Date: Thu, 23 Mar 2023 06:55:43 -0700 Subject: [PATCH] refactor: fix linter warnings Signed-off-by: Christian Stewart --- apigen/api_generate.go | 2 +- apigen/cmd_generate.go | 11 ++++++----- apigen/msg_func.go | 8 +------- apigen/msg_sender.go | 5 +---- client_match.go | 17 ----------------- socache/socache_container.go | 8 -------- 6 files changed, 9 insertions(+), 42 deletions(-) delete mode 100644 client_match.go diff --git a/apigen/api_generate.go b/apigen/api_generate.go index 9602be5..bf94546 100644 --- a/apigen/api_generate.go +++ b/apigen/api_generate.go @@ -260,7 +260,7 @@ func GenerateAPI(ctx context.Context, clientOutput, eventsOutput io.Writer) erro for _, eventHandler := range eventHandlersOrdered { fmt.Fprintf(eventsOutput, "\n") - fmt.Fprintf(eventsOutput, eventHandler.generateComment()) + fmt.Fprint(eventsOutput, eventHandler.generateComment()) fmt.Fprintf(eventsOutput, "type %s struct {\n", eventHandler.eventName) fmt.Fprintf(eventsOutput, "\t") if err := printFieldType(eventsOutput, eventHandler.eventType.Obj.Type()); err != nil { diff --git a/apigen/cmd_generate.go b/apigen/cmd_generate.go index 3268a07..3ae029c 100644 --- a/apigen/cmd_generate.go +++ b/apigen/cmd_generate.go @@ -3,9 +3,10 @@ package main import ( "bytes" "context" - "github.com/urfave/cli/v2" gofmt "go/format" - "io/ioutil" + "os" + + "github.com/urfave/cli/v2" ) var clientOutFile string @@ -37,7 +38,7 @@ func init() { return err } - if err := ioutil.WriteFile(clientOutFile, clientFileBuf.Bytes(), 0655); err != nil { + if err := os.WriteFile(clientOutFile, clientFileBuf.Bytes(), 0655); err != nil { return err } @@ -46,7 +47,7 @@ func init() { clientFileDat = clientFileBuf.Bytes() } - if err := ioutil.WriteFile(clientOutFile, clientFileDat, 0655); err != nil { + if err := os.WriteFile(clientOutFile, clientFileDat, 0655); err != nil { return err } @@ -59,7 +60,7 @@ func init() { eventsFileDat = eventsFileBuf.Bytes() } - if err := ioutil.WriteFile(eventsOutFile, eventsFileDat, 0655); err != nil { + if err := os.WriteFile(eventsOutFile, eventsFileDat, 0655); err != nil { return err } diff --git a/apigen/msg_func.go b/apigen/msg_func.go index a4f7537..57abd56 100644 --- a/apigen/msg_func.go +++ b/apigen/msg_func.go @@ -15,10 +15,7 @@ func GetMessageFuncName(msg dota_gcmessages_msgid.EDOTAGCMsg) string { msgName := msg.String() msgName = strings.TrimPrefix(msgName, "k_EMsg") - - if strings.HasPrefix(msgName, "DOTA") { - msgName = msgName[4:] - } + msgName = strings.TrimPrefix(msgName, "DOTA") switch { case strings.HasPrefix(msgName, "ClientToGC"): @@ -43,9 +40,6 @@ func GetMessageFuncName(msg dota_gcmessages_msgid.EDOTAGCMsg) string { if !IsWordVerb(words[0]) && IsWordVerb(words[1]) { words[0], words[1] = words[1], words[0] } - break - case IsWordVerb(words[0]): - break } switch { diff --git a/apigen/msg_sender.go b/apigen/msg_sender.go index 0a8c6d5..1b69e56 100644 --- a/apigen/msg_sender.go +++ b/apigen/msg_sender.go @@ -29,10 +29,7 @@ func GetMessageSender(msg protocol.EDOTAGCMsg) MsgSender { msgName := msg.String() msgName = msgName[6:] - - if strings.HasPrefix(msgName, "DOTA") { - msgName = msgName[4:] - } + msgName = strings.TrimPrefix(msgName, "DOTA") switch { case strings.HasPrefix(msgName, "SQL"): diff --git a/client_match.go b/client_match.go deleted file mode 100644 index 5d6455c..0000000 --- a/client_match.go +++ /dev/null @@ -1,17 +0,0 @@ -package dota2 - -import ( - "github.com/paralin/go-steam/protocol/gamecoordinator" - "github.com/paralin/go-dota2/events" -) - -// handleMatchSignedOut handles an incoming steam datagram ticket. -func (d *Dota2) handleMatchSignedOut(packet *gamecoordinator.GCPacket) error { - ev := &events.MatchSignedOut{} - if err := d.unmarshalBody(packet, &ev.CMsgGCToClientMatchSignedOut); err != nil { - return err - } - - d.emit(ev) - return nil -} diff --git a/socache/socache_container.go b/socache/socache_container.go index 9bf98e8..ec89050 100644 --- a/socache/socache_container.go +++ b/socache/socache_container.go @@ -4,7 +4,6 @@ import ( "math/rand" "sync" - "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -53,13 +52,6 @@ func (c *SOCacheContainer) parseObject(obj *gcsdkm.CMsgSOCacheSubscribed_Subscri return so, nil } -// stringifyObject converts an object to a json string. -func (c *SOCacheContainer) stringifyObject(obj proto.Message) string { - m := &jsonpb.Marshaler{} - str, _ := m.MarshalToString(obj) - return str -} - // emitEvent emits an event to all listeners. func (c *SOCacheContainer) emitEvent(event *CacheEvent) { c.subscriptions.Range(func(key interface{}, value interface{}) bool {