From 69db6cccce51be209d91cd0b8ee45460a03b4491 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Mon, 4 Dec 2023 17:54:24 +0100 Subject: [PATCH 1/2] refactor: remove error from analytics (#3802) * remove error from analytics * remove unused recover function * remove status parameter * remove unused struct --------- Co-authored-by: Pantani --- ignite/cmd/ignite/main.go | 9 ----- ignite/internal/analytics/analytics.go | 48 +++++--------------------- ignite/pkg/gacli/gacli.go | 2 -- 3 files changed, 8 insertions(+), 51 deletions(-) diff --git a/ignite/cmd/ignite/main.go b/ignite/cmd/ignite/main.go index f61a3f611b..ec55e86435 100644 --- a/ignite/cmd/ignite/main.go +++ b/ignite/cmd/ignite/main.go @@ -24,15 +24,6 @@ func main() { func run() int { const exitCodeOK, exitCodeError = 0, 1 var wg sync.WaitGroup - - defer func() { - if r := recover(); r != nil { - analytics.SendMetric(&wg, os.Args, analytics.WithError(fmt.Errorf("%v", r))) - fmt.Println(r) - os.Exit(exitCodeError) - } - }() - if len(os.Args) > 1 { analytics.SendMetric(&wg, os.Args) } diff --git a/ignite/internal/analytics/analytics.go b/ignite/internal/analytics/analytics.go index 6bc8367caa..55338c279b 100644 --- a/ignite/internal/analytics/analytics.go +++ b/ignite/internal/analytics/analytics.go @@ -24,49 +24,25 @@ const ( var gaclient gacli.Client -type ( - // metric represents an analytics metric. - options struct { - // err sets metrics type as an error metric. - err error - } - - // anonIdentity represents an analytics identity file. - anonIdentity struct { - // name represents the username. - Name string `json:"name" yaml:"name"` - // doNotTrack represents the user track choice. - DoNotTrack bool `json:"doNotTrack" yaml:"doNotTrack"` - } -) +// anonIdentity represents an analytics identity file. +type anonIdentity struct { + // name represents the username. + Name string `json:"name" yaml:"name"` + // doNotTrack represents the user track choice. + DoNotTrack bool `json:"doNotTrack" yaml:"doNotTrack"` +} func init() { gaclient = gacli.New(telemetryEndpoint) } -// Option configures ChainCmd. -type Option func(*options) - -// WithError with application command error. -func WithError(error error) Option { - return func(m *options) { - m.err = error - } -} - // SendMetric send command metrics to analytics. -func SendMetric(wg *sync.WaitGroup, args []string, opts ...Option) { +func SendMetric(wg *sync.WaitGroup, args []string) { // only the app name if len(args) <= 1 { return } - // apply analytics options. - var opt options - for _, o := range opts { - o(&opt) - } - if args[1] == "version" { return } @@ -83,14 +59,6 @@ func SendMetric(wg *sync.WaitGroup, args []string, opts ...Option) { SessionID: dntInfo.Name, Version: version.Version, } - - switch { - case opt.err == nil: - met.Status = "success" - case opt.err != nil: - met.Status = "error" - met.Error = opt.err.Error() - } met.Cmd = args[1] wg.Add(1) diff --git a/ignite/pkg/gacli/gacli.go b/ignite/pkg/gacli/gacli.go index 7237bcd50b..310cf139f2 100644 --- a/ignite/pkg/gacli/gacli.go +++ b/ignite/pkg/gacli/gacli.go @@ -29,12 +29,10 @@ type ( } // Metric represents a data point. Metric struct { - Status string `json:"status,omitempty"` OS string `json:"os,omitempty"` Arch string `json:"arch,omitempty"` FullCmd string `json:"full_command,omitempty"` Cmd string `json:"command,omitempty"` - Error string `json:"error,omitempty"` Version string `json:"version,omitempty"` SessionID string `json:"session_id,omitempty"` EngagementTimeMsec string `json:"engagement_time_msec,omitempty"` From d6595bde663ffffd53af255d13219e3ae89c220e Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Mon, 4 Dec 2023 21:25:22 +0100 Subject: [PATCH 2/2] chore: use `fmt.Sprintf` instead concatenating strings (#3801) * use fmt.Sprintf instead string add * add missing sprintf to proto query --------- Co-authored-by: Pantani --- ignite/pkg/gomodule/gomodule_test.go | 3 +- ignite/services/scaffolder/component.go | 26 +++++----- ignite/templates/ibc/packet.go | 8 ++- ignite/templates/message/message.go | 9 +++- ignite/templates/query/query.go | 5 +- ignite/templates/typed/list/list.go | 50 +++++++++++++------ ignite/templates/typed/map/map.go | 44 +++++++++++----- ignite/templates/typed/singleton/singleton.go | 31 +++++++++--- 8 files changed, 122 insertions(+), 54 deletions(-) diff --git a/ignite/pkg/gomodule/gomodule_test.go b/ignite/pkg/gomodule/gomodule_test.go index 42ff3e6d2a..2c453ecd28 100644 --- a/ignite/pkg/gomodule/gomodule_test.go +++ b/ignite/pkg/gomodule/gomodule_test.go @@ -5,8 +5,9 @@ import ( "strings" "testing" - "github.com/ignite/cli/ignite/pkg/gomodule" "github.com/stretchr/testify/require" + + "github.com/ignite/cli/ignite/pkg/gomodule" ) func TestSplitPath(t *testing.T) { diff --git a/ignite/services/scaffolder/component.go b/ignite/services/scaffolder/component.go index eddcbb59e0..507fbf8666 100644 --- a/ignite/services/scaffolder/component.go +++ b/ignite/services/scaffolder/component.go @@ -48,22 +48,22 @@ func checkComponentValidity(appPath, moduleName string, compName multiformatname func checkComponentCreated(appPath, moduleName string, compName multiformatname.Name, noMessage bool) (err error) { // associate the type to check with the component that scaffold this type typesToCheck := map[string]string{ - compName.UpperCamel: componentType, - "queryall" + compName.LowerCase + "request": componentType, - "queryall" + compName.LowerCase + "response": componentType, - "queryget" + compName.LowerCase + "request": componentType, - "queryget" + compName.LowerCase + "response": componentType, - "query" + compName.LowerCase + "request": componentQuery, - "query" + compName.LowerCase + "response": componentQuery, - compName.LowerCase + "packetdata": componentPacket, + compName.UpperCamel: componentType, + fmt.Sprintf("queryall%srequest", compName.LowerCase): componentType, + fmt.Sprintf("queryall%sresponse", compName.LowerCase): componentType, + fmt.Sprintf("queryget%srequest", compName.LowerCase): componentType, + fmt.Sprintf("queryget%sresponse", compName.LowerCase): componentType, + fmt.Sprintf("query%srequest", compName.LowerCase): componentQuery, + fmt.Sprintf("query%sresponse", compName.LowerCase): componentQuery, + fmt.Sprintf("%spacketdata", compName.LowerCase): componentPacket, } if !noMessage { - typesToCheck["msgcreate"+compName.LowerCase] = componentType - typesToCheck["msgupdate"+compName.LowerCase] = componentType - typesToCheck["msgdelete"+compName.LowerCase] = componentType - typesToCheck["msg"+compName.LowerCase] = componentMessage - typesToCheck["msgsend"+compName.LowerCase] = componentPacket + typesToCheck[fmt.Sprintf("msgcreate%s", compName.LowerCase)] = componentType + typesToCheck[fmt.Sprintf("msgupdate%s", compName.LowerCase)] = componentType + typesToCheck[fmt.Sprintf("msgdelete%s", compName.LowerCase)] = componentType + typesToCheck[fmt.Sprintf("msg%s", compName.LowerCase)] = componentMessage + typesToCheck[fmt.Sprintf("msgsend%s", compName.LowerCase)] = componentPacket } absPath, err := filepath.Abs(filepath.Join(appPath, "x", moduleName, "types")) diff --git a/ignite/templates/ibc/packet.go b/ignite/templates/ibc/packet.go index d8a4e5002e..0519f05ae7 100644 --- a/ignite/templates/ibc/packet.go +++ b/ignite/templates/ibc/packet.go @@ -191,7 +191,7 @@ func protoModify(opts *PacketOptions) genny.RunFn { if err != nil { return err } - name := xstrings.Title(opts.ModuleName) + "PacketData" + name := fmt.Sprintf("%sPacketData", xstrings.Title(opts.ModuleName)) message, err := protoutil.GetMessageByName(protoFile, name) if err != nil { return fmt.Errorf("failed while looking up '%s' message in %s: %w", name, path, err) @@ -305,7 +305,11 @@ func protoTxModify(opts *PacketOptions) genny.RunFn { return fmt.Errorf("failed while looking up service 'Msg' in %s: %w", path, err) } typenameUpper := opts.PacketName.UpperCamel - send := protoutil.NewRPC("Send"+typenameUpper, "MsgSend"+typenameUpper, "MsgSend"+typenameUpper+"Response") + send := protoutil.NewRPC( + fmt.Sprintf("Send%s", typenameUpper), + fmt.Sprintf("MsgSend%s", typenameUpper), + fmt.Sprintf("MsgSend%sResponse", typenameUpper), + ) protoutil.Append(serviceMsg, send) // Create fields for MsgSend. diff --git a/ignite/templates/message/message.go b/ignite/templates/message/message.go index 4f292bcf90..a944edff25 100644 --- a/ignite/templates/message/message.go +++ b/ignite/templates/message/message.go @@ -101,7 +101,14 @@ func protoTxRPCModify(opts *Options) genny.RunFn { return fmt.Errorf("failed while looking up service 'Msg' in %s: %w", path, err) } typenameUpper := opts.MsgName.UpperCamel - protoutil.Append(serviceMsg, protoutil.NewRPC(typenameUpper, "Msg"+typenameUpper, "Msg"+typenameUpper+"Response")) + protoutil.Append( + serviceMsg, + protoutil.NewRPC( + typenameUpper, + fmt.Sprintf("Msg%s", typenameUpper), + fmt.Sprintf("Msg%sResponse", typenameUpper), + ), + ) newFile := genny.NewFileS(path, protoutil.Print(protoFile)) return r.File(newFile) diff --git a/ignite/templates/query/query.go b/ignite/templates/query/query.go index 6483e4e249..5d9b0ca0e0 100644 --- a/ignite/templates/query/query.go +++ b/ignite/templates/query/query.go @@ -89,7 +89,10 @@ func protoQueryModify(opts *Options) genny.RunFn { } typenameUpper, appModulePath := opts.QueryName.UpperCamel, gomodulepath.ExtractAppPath(opts.ModulePath) - rpcSingle := protoutil.NewRPC(typenameUpper, "Query"+typenameUpper+"Request", "Query"+typenameUpper+"Response", + rpcSingle := protoutil.NewRPC( + typenameUpper, + fmt.Sprintf("Query%sRequest", typenameUpper), + fmt.Sprintf("Query%sResponse", typenameUpper), protoutil.WithRPCOptions( protoutil.NewOption( "google.api.http", diff --git a/ignite/templates/typed/list/list.go b/ignite/templates/typed/list/list.go index e3603b5ff8..67cdab08bb 100644 --- a/ignite/templates/typed/list/list.go +++ b/ignite/templates/typed/list/list.go @@ -110,9 +110,21 @@ func protoTxModify(opts *typed.Options) genny.RunFn { // Create, update, delete rpcs. Better to append them altogether, single traversal. typenameUpper := opts.TypeName.UpperCamel protoutil.Append(serviceMsg, - protoutil.NewRPC("Create"+typenameUpper, "MsgCreate"+typenameUpper, "MsgCreate"+typenameUpper+"Response"), - protoutil.NewRPC("Update"+typenameUpper, "MsgUpdate"+typenameUpper, "MsgUpdate"+typenameUpper+"Response"), - protoutil.NewRPC("Delete"+typenameUpper, "MsgDelete"+typenameUpper, "MsgDelete"+typenameUpper+"Response"), + protoutil.NewRPC( + fmt.Sprintf("Create%s", typenameUpper), + fmt.Sprintf("MsgCreate%s", typenameUpper), + fmt.Sprintf("MsgCreate%sResponse", typenameUpper), + ), + protoutil.NewRPC( + fmt.Sprintf("Update%s", typenameUpper), + fmt.Sprintf("MsgUpdate%s", typenameUpper), + fmt.Sprintf("MsgUpdate%sResponse", typenameUpper), + ), + protoutil.NewRPC( + fmt.Sprintf("Delete%s", typenameUpper), + fmt.Sprintf("MsgDelete%s", typenameUpper), + fmt.Sprintf("MsgDelete%sResponse", typenameUpper), + ), ) // - Ensure custom types are imported @@ -142,26 +154,26 @@ func protoTxModify(opts *typed.Options) genny.RunFn { } msgCreate := protoutil.NewMessage( - "MsgCreate"+typenameUpper, + fmt.Sprintf("MsgCreate%s", typenameUpper), protoutil.WithFields(createFields...), protoutil.WithMessageOptions(creatorOpt), ) msgCreateResponse := protoutil.NewMessage( - "MsgCreate"+typenameUpper+"Response", + fmt.Sprintf("MsgCreate%sResponse", typenameUpper), protoutil.WithFields(protoutil.NewField("id", "uint64", 1)), ) msgUpdate := protoutil.NewMessage( - "MsgUpdate"+typenameUpper, + fmt.Sprintf("MsgUpdate%s", typenameUpper), protoutil.WithFields(updateFields...), protoutil.WithMessageOptions(creatorOpt), ) - msgUpdateResponse := protoutil.NewMessage("MsgUpdate" + typenameUpper + "Response") + msgUpdateResponse := protoutil.NewMessage(fmt.Sprintf("MsgUpdate%sResponse", typenameUpper)) msgDelete := protoutil.NewMessage( - "MsgDelete"+typenameUpper, + fmt.Sprintf("MsgDelete%s", typenameUpper), protoutil.WithFields(udfields...), protoutil.WithMessageOptions(creatorOpt), ) - msgDeleteResponse := protoutil.NewMessage("MsgDelete" + typenameUpper + "Response") + msgDeleteResponse := protoutil.NewMessage(fmt.Sprintf("MsgDelete%sResponse", typenameUpper)) protoutil.Append( protoFile, msgCreate, @@ -205,7 +217,10 @@ func protoQueryModify(opts *typed.Options) genny.RunFn { } appModulePath := gomodulepath.ExtractAppPath(opts.ModulePath) typenameUpper := opts.TypeName.UpperCamel - rpcQueryGet := protoutil.NewRPC(typenameUpper, "QueryGet"+typenameUpper+"Request", "QueryGet"+typenameUpper+"Response", + rpcQueryGet := protoutil.NewRPC( + typenameUpper, + fmt.Sprintf("QueryGet%sRequest", typenameUpper), + fmt.Sprintf("QueryGet%sResponse", typenameUpper), protoutil.WithRPCOptions( protoutil.NewOption( "google.api.http", @@ -220,7 +235,10 @@ func protoQueryModify(opts *typed.Options) genny.RunFn { ) protoutil.AttachComment(rpcQueryGet, fmt.Sprintf("Queries a %v by id.", typenameUpper)) - rpcQueryAll := protoutil.NewRPC(typenameUpper+"All", "QueryAll"+typenameUpper+"Request", "QueryAll"+typenameUpper+"Response", + rpcQueryAll := protoutil.NewRPC( + fmt.Sprintf("%sAll", typenameUpper), + fmt.Sprintf("QueryAll%sRequest", typenameUpper), + fmt.Sprintf("QueryAll%sResponse", typenameUpper), protoutil.WithRPCOptions( protoutil.NewOption( "google.api.http", @@ -241,19 +259,21 @@ func protoQueryModify(opts *typed.Options) genny.RunFn { gogoOption := protoutil.NewOption("gogoproto.nullable", "false", protoutil.Custom()) queryGetRequest := protoutil.NewMessage( - "QueryGet"+typenameUpper+"Request", + fmt.Sprintf("QueryGet%sRequest", typenameUpper), protoutil.WithFields(protoutil.NewField("id", "uint64", 1)), ) field := protoutil.NewField(typenameUpper, typenameUpper, 1, protoutil.WithFieldOptions(gogoOption)) - queryGetResponse := protoutil.NewMessage("QueryGet"+typenameUpper+"Response", protoutil.WithFields(field)) + queryGetResponse := protoutil.NewMessage( + fmt.Sprintf("QueryGet%sResponse", typenameUpper), + protoutil.WithFields(field)) queryAllRequest := protoutil.NewMessage( - "QueryAll"+typenameUpper+"Request", + fmt.Sprintf("QueryAll%sRequest", typenameUpper), protoutil.WithFields(protoutil.NewField(paginationName, paginationType+"Request", 1)), ) field = protoutil.NewField(typenameUpper, typenameUpper, 1, protoutil.Repeated(), protoutil.WithFieldOptions(gogoOption)) queryAllResponse := protoutil.NewMessage( - "QueryAll"+typenameUpper+"Response", + fmt.Sprintf("QueryAll%sResponse", typenameUpper), protoutil.WithFields(field, protoutil.NewField(paginationName, paginationType+"Response", 2)), ) protoutil.Append(protoFile, queryGetRequest, queryGetResponse, queryAllRequest, queryAllResponse) diff --git a/ignite/templates/typed/map/map.go b/ignite/templates/typed/map/map.go index 5e60c4b4bb..4a1ed3ad46 100644 --- a/ignite/templates/typed/map/map.go +++ b/ignite/templates/typed/map/map.go @@ -149,7 +149,10 @@ func protoRPCModify(opts *typed.Options) genny.RunFn { return fmt.Errorf("failed while looking up service 'Query' in %s: %w", path, err) } typenameUpper, typenameSnake, typenameLower := opts.TypeName.UpperCamel, opts.TypeName.Snake, opts.TypeName.LowerCamel - rpcQueryGet := protoutil.NewRPC(typenameUpper, "QueryGet"+typenameUpper+"Request", "QueryGet"+typenameUpper+"Response", + rpcQueryGet := protoutil.NewRPC( + typenameUpper, + fmt.Sprintf("QueryGet%sRequest", typenameUpper), + fmt.Sprintf("QueryGet%sResponse", typenameUpper), protoutil.WithRPCOptions( protoutil.NewOption( "google.api.http", @@ -164,7 +167,10 @@ func protoRPCModify(opts *typed.Options) genny.RunFn { ) protoutil.AttachComment(rpcQueryGet, fmt.Sprintf("Queries a %v by index.", typenameUpper)) - rpcQueryAll := protoutil.NewRPC(typenameUpper+"All", "QueryAll"+typenameUpper+"Request", "QueryAll"+typenameUpper+"Response", + rpcQueryAll := protoutil.NewRPC( + fmt.Sprintf("%sAll", typenameUpper), + fmt.Sprintf("QueryAll%sRequest", typenameUpper), + fmt.Sprintf("QueryAll%sResponse", typenameUpper), protoutil.WithRPCOptions( protoutil.NewOption( "google.api.http", @@ -202,20 +208,20 @@ func protoRPCModify(opts *typed.Options) genny.RunFn { } paginationType, paginationName := "cosmos.base.query.v1beta1.Page", "pagination" queryGetRequest := protoutil.NewMessage( - "QueryGet"+typenameUpper+"Request", + fmt.Sprintf("QueryGet%sRequest", typenameUpper), protoutil.WithFields(queryIndexFields...), ) gogoOption := protoutil.NewOption("gogoproto.nullable", "false", protoutil.Custom()) queryGetResponse := protoutil.NewMessage( - "QueryGet"+typenameUpper+"Response", + fmt.Sprintf("QueryGet%sResponse", typenameUpper), protoutil.WithFields(protoutil.NewField(typenameLower, typenameUpper, 1, protoutil.WithFieldOptions(gogoOption))), ) queryAllRequest := protoutil.NewMessage( - "QueryAll"+typenameUpper+"Request", + fmt.Sprintf("QueryAll%sRequest", typenameUpper), protoutil.WithFields(protoutil.NewField(paginationName, paginationType+"Request", 1)), ) queryAllResponse := protoutil.NewMessage( - "QueryAll"+typenameUpper+"Response", + fmt.Sprintf("QueryAll%sResponse", typenameUpper), protoutil.WithFields( protoutil.NewField( typenameLower, @@ -224,7 +230,7 @@ func protoRPCModify(opts *typed.Options) genny.RunFn { protoutil.Repeated(), protoutil.WithFieldOptions(gogoOption), ), - protoutil.NewField(paginationName, paginationType+"Response", 2), + protoutil.NewField(paginationName, fmt.Sprintf("%sResponse", paginationType), 2), ), ) protoutil.Append(protoFile, queryGetRequest, queryGetResponse, queryAllRequest, queryAllResponse) @@ -537,9 +543,21 @@ func protoTxModify(opts *typed.Options) genny.RunFn { // better to append them altogether, single traversal. typenameUpper := opts.TypeName.UpperCamel protoutil.Append(serviceMsg, - protoutil.NewRPC("Create"+typenameUpper, "MsgCreate"+typenameUpper, "MsgCreate"+typenameUpper+"Response"), - protoutil.NewRPC("Update"+typenameUpper, "MsgUpdate"+typenameUpper, "MsgUpdate"+typenameUpper+"Response"), - protoutil.NewRPC("Delete"+typenameUpper, "MsgDelete"+typenameUpper, "MsgDelete"+typenameUpper+"Response"), + protoutil.NewRPC( + fmt.Sprintf("Create%s", typenameUpper), + fmt.Sprintf("MsgCreate%s", typenameUpper), + fmt.Sprintf("MsgCreate%sResponse", typenameUpper), + ), + protoutil.NewRPC( + fmt.Sprintf("Update%s", typenameUpper), + fmt.Sprintf("MsgUpdate%s", typenameUpper), + fmt.Sprintf("MsgUpdate%sResponse", typenameUpper), + ), + protoutil.NewRPC( + fmt.Sprintf("Delete%s", typenameUpper), + fmt.Sprintf("MsgDelete%s", typenameUpper), + fmt.Sprintf("MsgDelete%sResponse", typenameUpper), + ), ) // Messages @@ -577,21 +595,21 @@ func protoTxModify(opts *typed.Options) genny.RunFn { protoutil.WithFields(append(commonFields, fields...)...), protoutil.WithMessageOptions(creatorOpt), ) - msgCreateResponse := protoutil.NewMessage("MsgCreate" + typenameUpper + "Response") + msgCreateResponse := protoutil.NewMessage(fmt.Sprintf("MsgCreate%sResponse", typenameUpper)) msgUpdate := protoutil.NewMessage( "MsgUpdate"+typenameUpper, protoutil.WithFields(append(commonFields, fields...)...), protoutil.WithMessageOptions(creatorOpt), ) - msgUpdateResponse := protoutil.NewMessage("MsgUpdate" + typenameUpper + "Response") + msgUpdateResponse := protoutil.NewMessage(fmt.Sprintf("MsgUpdate%sResponse", typenameUpper)) msgDelete := protoutil.NewMessage( "MsgDelete"+typenameUpper, protoutil.WithFields(commonFields...), protoutil.WithMessageOptions(creatorOpt), ) - msgDeleteResponse := protoutil.NewMessage("MsgDelete" + typenameUpper + "Response") + msgDeleteResponse := protoutil.NewMessage(fmt.Sprintf("MsgDelete%sResponse", typenameUpper)) protoutil.Append(protoFile, msgCreate, msgCreateResponse, msgUpdate, msgUpdateResponse, msgDelete, msgDeleteResponse, ) diff --git a/ignite/templates/typed/singleton/singleton.go b/ignite/templates/typed/singleton/singleton.go index 9059678129..343adbe961 100644 --- a/ignite/templates/typed/singleton/singleton.go +++ b/ignite/templates/typed/singleton/singleton.go @@ -127,7 +127,10 @@ func protoRPCModify(opts *typed.Options) genny.RunFn { } appModulePath := gomodulepath.ExtractAppPath(opts.ModulePath) typenameUpper := opts.TypeName.UpperCamel - rpcQueryGet := protoutil.NewRPC(typenameUpper, "QueryGet"+typenameUpper+"Request", "QueryGet"+typenameUpper+"Response", + rpcQueryGet := protoutil.NewRPC( + typenameUpper, + fmt.Sprintf("QueryGet%sRequest", typenameUpper), + fmt.Sprintf("QueryGet%sResponse", typenameUpper), protoutil.WithRPCOptions( protoutil.NewOption( "google.api.http", @@ -148,7 +151,7 @@ func protoRPCModify(opts *typed.Options) genny.RunFn { field := protoutil.NewField(typenameUpper, typenameUpper, 1, protoutil.WithFieldOptions(protoutil.NewOption("gogoproto.nullable", "false", protoutil.Custom())), ) - queryGetResponse := protoutil.NewMessage("QueryGet"+typenameUpper+"Response", protoutil.WithFields(field)) + queryGetResponse := protoutil.NewMessage(fmt.Sprintf("QueryGet%sResponse", typenameUpper), protoutil.WithFields(field)) protoutil.Append(protoFile, queryGetRequest, queryGetResponse) newFile := genny.NewFileS(path, protoutil.Print(protoFile)) @@ -383,9 +386,21 @@ func protoTxModify(opts *typed.Options) genny.RunFn { // Append create, update, delete rpcs. Better to append them altogether, single traversal. name := opts.TypeName.UpperCamel protoutil.Append(serviceMsg, - protoutil.NewRPC("Create"+name, "MsgCreate"+name, "MsgCreate"+name+"Response"), - protoutil.NewRPC("Update"+name, "MsgUpdate"+name, "MsgUpdate"+name+"Response"), - protoutil.NewRPC("Delete"+name, "MsgDelete"+name, "MsgDelete"+name+"Response"), + protoutil.NewRPC( + fmt.Sprintf("Create%s", name), + fmt.Sprintf("MsgCreate%s", name), + fmt.Sprintf("MsgCreate%sResponse", name), + ), + protoutil.NewRPC( + fmt.Sprintf("Update%s", name), + fmt.Sprintf("MsgUpdate%s", name), + fmt.Sprintf("MsgUpdate%sResponse", name), + ), + protoutil.NewRPC( + fmt.Sprintf("Delete%s", name), + fmt.Sprintf("MsgDelete%s", name), + fmt.Sprintf("MsgDelete%sResponse", name), + ), ) // Ensure custom types are imported @@ -415,19 +430,19 @@ func protoTxModify(opts *typed.Options) genny.RunFn { protoutil.WithFields(fields...), protoutil.WithMessageOptions(creatorOpt), ) - msgCreateResponse := protoutil.NewMessage("MsgCreate" + name + "Response") + msgCreateResponse := protoutil.NewMessage(fmt.Sprintf("MsgCreate%sResponse", name)) msgUpdate := protoutil.NewMessage( "MsgUpdate"+name, protoutil.WithFields(fields...), protoutil.WithMessageOptions(creatorOpt), ) - msgUpdateResponse := protoutil.NewMessage("MsgUpdate" + name + "Response") + msgUpdateResponse := protoutil.NewMessage(fmt.Sprintf("MsgUpdate%sResponse", name)) msgDelete := protoutil.NewMessage( "MsgDelete"+name, protoutil.WithFields(creator), protoutil.WithMessageOptions(creatorOpt), ) - msgDeleteResponse := protoutil.NewMessage("MsgDelete" + name + "Response") + msgDeleteResponse := protoutil.NewMessage(fmt.Sprintf("MsgDelete%sResponse", name)) protoutil.Append(protoFile, msgCreate, msgCreateResponse, msgUpdate, msgUpdateResponse, msgDelete, msgDeleteResponse, )