@@ -19,11 +19,13 @@ import (
1919 "github.com/pubgo/funk/v2/stack"
2020)
2121
22- var cloudeventPkg = reflect .TypeOf (cloudevent.Client {}).PkgPath ()
23- var jobTypesPkg = reflect .TypeOf (cloudeventpb.PushEventOptions {}).PkgPath ()
24- var ctxPkg = stack .CallerWithFunc (context .WithTimeout ).Pkg
25- var assertPkt = stack .CallerWithFunc (assert .Assert ).Pkg
26- var protojsonPkt = stack .CallerWithFunc (protojson .Marshal ).Pkg
22+ var (
23+ cloudeventPkg = reflect .TypeOf (cloudevent.Client {}).PkgPath ()
24+ jobTypesPkg = reflect .TypeOf (cloudeventpb.PushEventOptions {}).PkgPath ()
25+ ctxPkg = stack .CallerWithFunc (context .WithTimeout ).Pkg
26+ assertPkt = stack .CallerWithFunc (assert .Assert ).Pkg
27+ protojsonPkt = stack .CallerWithFunc (protojson .Marshal ).Pkg
28+ )
2729
2830type eventInfo struct {
2931 srv * protogen.Service
@@ -54,7 +56,7 @@ func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
5456 return g
5557 }
5658
57- var events = make (map [string ]map [string ]* eventInfo )
59+ events : = make (map [string ]map [string ]* eventInfo )
5860 for _ , srv := range file .Services {
5961 job , ok := proto .GetExtension (srv .Desc .Options (), cloudeventpb .E_Job ).(* cloudeventpb.CloudEventServiceOptions )
6062 if ! ok || job == nil {
@@ -118,7 +120,7 @@ func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
118120
119121 for _ , subName := range subjectNames {
120122 info := subjects [subName ]
121- var keyName = fmt .Sprintf ("%sCloudEventKey" , info .mth .GoName )
123+ keyName : = fmt .Sprintf ("%sCloudEventKey" , info .mth .GoName )
122124 genFile .Commentf ("%s /%s/%s" , keyName , info .srv .Desc .FullName (), info .mth .GoName )
123125 genFile .Comment (strings .TrimSpace (info .mth .Comments .Leading .String ()))
124126 genFile .Const ().
@@ -147,7 +149,7 @@ func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
147149 //}
148150
149151 subjectValues := lo .Values (subjects )
150- var cloudEventName = fmt .Sprintf ("%sCloudEvent" , subjectValues [0 ].srv .GoName )
152+ cloudEventName : = fmt .Sprintf ("%sCloudEvent" , subjectValues [0 ].srv .GoName )
151153 genFile .Type ().Id (cloudEventName ).StructFunc (func (group * jen.Group ) {
152154 for _ , ss := range subjectValues {
153155 group .Id ("On" + ss .mth .GoName ).Func ().Params (
@@ -165,27 +167,27 @@ func GenerateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated
165167 jen .Id ("opts" ).Op ("..." ).Op ("*" ).Qual (jobTypesPkg , "RegisterJobOptions" ),
166168 ).BlockFunc (func (group * jen.Group ) {
167169 for _ , ss := range subjectValues {
168- var keyName = fmt .Sprintf ("%sCloudEventKey" , ss .mth .GoName )
170+ keyName : = fmt .Sprintf ("%sCloudEventKey" , ss .mth .GoName )
169171 group .If (jen .Id ("event" ).Dot ("On" + ss .mth .GoName )).Op ("!=" ).Nil ().BlockFunc (func (group * jen.Group ) {
170172 group .Qual (cloudeventPkg , "RegisterJobHandler" ).Call (
171173 jen .Id ("jobCli" ),
172174 jen .Id (jobKeyName ),
173175 jen .Id (keyName ),
174176 jen .Id ("event" ).Dot ("On" + ss .mth .GoName ),
175- //jen.Qual(cloudeventPkg, "WrapHandler").Call(jen.Id("event").Dot(ss.mth.GoName)),
177+ // jen.Qual(cloudeventPkg, "WrapHandler").Call(jen.Id("event").Dot(ss.mth.GoName)),
176178 jen .Id ("opts" ).Op ("..." ),
177179 )
178180 }).Line ()
179181 }
180182 })
181183
182- var publisher = fmt .Sprintf ("%sPublisher" , cloudEventName )
184+ publisher : = fmt .Sprintf ("%sPublisher" , cloudEventName )
183185 genFile .Type ().Id (publisher ).StructFunc (func (group * jen.Group ) {
184186 group .Id ("Client" ).Op ("*" ).Qual (cloudeventPkg , "Client" )
185187 })
186188 for _ , ss := range subjectValues {
187- var mthName = fmt .Sprintf ("Push%sEvent" , ss .mth .GoName )
188- var keyName = fmt .Sprintf ("%sCloudEventKey" , ss .mth .GoName )
189+ mthName : = fmt .Sprintf ("Push%sEvent" , ss .mth .GoName )
190+ keyName : = fmt .Sprintf ("%sCloudEventKey" , ss .mth .GoName )
189191 genFile .Func ().
190192 Params (jen .Id (fmt .Sprintf ("a %s" , publisher ))).
191193 Id (mthName ).
@@ -223,7 +225,7 @@ func getSrv(data map[string]*eventInfo) *protogen.Service {
223225}
224226
225227func getPkg (file * protogen.File , goIdent protogen.GoIdent ) * jen.Statement {
226- var pkgName = ""
228+ pkgName : = ""
227229 if file .GoImportPath != goIdent .GoImportPath {
228230 pkgName = string (goIdent .GoImportPath )
229231 }
0 commit comments