@@ -117,7 +117,7 @@ func geninit(file *protogen.File, g *protogen.GeneratedFile) {
117
117
g .P ("var e error" )
118
118
for reg := range allreg {
119
119
g .P ("if _" , service .GoName , "WebRegs[" , strconv .Quote (reg ), "] ,e = " , g .QualifiedGoIdent (regexpPackage .Ident ("Compile" )), "(" , strconv .Quote (reg ), ");e!=nil{" )
120
- g .P ("panic(\" protoc-gen-go-rpc will check all regexp before generate this code,this may happen when the golang version build protoc-gen-go-rpc and golang version run this code isn't same and the two version's regexp package is different\" )" )
120
+ g .P ("panic(\" protoc-gen-go-web will check all regexp before generate this code,this may happen when the golang version build protoc-gen-go-web and golang version run this code isn't same and the two version's regexp package is different\" )" )
121
121
g .P ("}" )
122
122
}
123
123
g .P ()
@@ -1136,9 +1136,9 @@ func strcheck(prefix string, field *protogen.Field, isslice bool, fop *descripto
1136
1136
g .P ("for _,v:=range " , prefix + field .GoName , "{" )
1137
1137
for _ , m := range match {
1138
1138
if isslice {
1139
- g .P ("if !_" , service .GoName , "RpcRegs [" , strconv .Quote (m ), "].Match(v){" )
1139
+ g .P ("if !_" , service .GoName , "WebRegs [" , strconv .Quote (m ), "].Match(v){" )
1140
1140
} else {
1141
- g .P ("if !_" , service .GoName , "RpcRegs [" , strconv .Quote (m ), "].MatchString(v){" )
1141
+ g .P ("if !_" , service .GoName , "WebRegs [" , strconv .Quote (m ), "].MatchString(v){" )
1142
1142
}
1143
1143
g .P ("return \" field: " , string (field .Desc .Name ()), " in object: " , string (field .Parent .Desc .Name ()), " check value str match failed\" " )
1144
1144
//g.P(g.QualifiedGoIdent(logPackage.Ident("Error")), "(\"field: ", string(field.Desc.Name()), " in object: ", string(field.Parent.Desc.Name()), " check value str match failed\")")
@@ -1149,9 +1149,9 @@ func strcheck(prefix string, field *protogen.Field, isslice bool, fop *descripto
1149
1149
} else {
1150
1150
for _ , m := range match {
1151
1151
if isslice {
1152
- g .P ("if !_" , service .GoName , "RpcRegs [" , strconv .Quote (m ), "].Match(" , prefix + field .GoName , "){" )
1152
+ g .P ("if !_" , service .GoName , "WebRegs [" , strconv .Quote (m ), "].Match(" , prefix + field .GoName , "){" )
1153
1153
} else {
1154
- g .P ("if !_" , service .GoName , "RpcRegs [" , strconv .Quote (m ), "].MatchString(" , prefix + field .GoName , "){" )
1154
+ g .P ("if !_" , service .GoName , "WebRegs [" , strconv .Quote (m ), "].MatchString(" , prefix + field .GoName , "){" )
1155
1155
}
1156
1156
g .P ("return \" field: " , string (field .Desc .Name ()), " in object: " , string (field .Parent .Desc .Name ()), " check value str match failed\" " )
1157
1157
//g.P(g.QualifiedGoIdent(logPackage.Ident("Error")), "(\"field: ", string(field.Desc.Name()), " in object: ", string(field.Parent.Desc.Name()), " check value str match failed\")")
@@ -1166,9 +1166,9 @@ func strcheck(prefix string, field *protogen.Field, isslice bool, fop *descripto
1166
1166
g .P ("for _,v:=range " , prefix + field .GoName , "{" )
1167
1167
for _ , m := range notmatch {
1168
1168
if isslice {
1169
- g .P ("if _" , service .GoName , "RpcRegs [" , strconv .Quote (m ), "].Match(v){" )
1169
+ g .P ("if _" , service .GoName , "WebRegs [" , strconv .Quote (m ), "].Match(v){" )
1170
1170
} else {
1171
- g .P ("if _" , service .GoName , "RpcRegs [" , strconv .Quote (m ), "].MatchString(v){" )
1171
+ g .P ("if _" , service .GoName , "WebRegs [" , strconv .Quote (m ), "].MatchString(v){" )
1172
1172
}
1173
1173
g .P ("return \" field: " , string (field .Desc .Name ()), " in object: " , string (field .Parent .Desc .Name ()), " check value str not match failed\" " )
1174
1174
//g.P(g.QualifiedGoIdent(logPackage.Ident("Error")), "(\"field: ", string(field.Desc.Name()), " in object: ", string(field.Parent.Desc.Name()), " check value str not match failed\")")
@@ -1179,9 +1179,9 @@ func strcheck(prefix string, field *protogen.Field, isslice bool, fop *descripto
1179
1179
} else {
1180
1180
for _ , m := range notmatch {
1181
1181
if isslice {
1182
- g .P ("if _" , service .GoName , "RpcRegs [" , strconv .Quote (m ), "].Match(" , prefix + field .GoName , "){" )
1182
+ g .P ("if _" , service .GoName , "WebRegs [" , strconv .Quote (m ), "].Match(" , prefix + field .GoName , "){" )
1183
1183
} else {
1184
- g .P ("if _" , service .GoName , "RpcRegs [" , strconv .Quote (m ), "].MatchString(" , prefix + field .GoName , "){" )
1184
+ g .P ("if _" , service .GoName , "WebRegs [" , strconv .Quote (m ), "].MatchString(" , prefix + field .GoName , "){" )
1185
1185
}
1186
1186
g .P ("return \" field: " , string (field .Desc .Name ()), " in object: " , string (field .Parent .Desc .Name ()), " check value str not match failed\" " )
1187
1187
//g.P(g.QualifiedGoIdent(logPackage.Ident("Error")), "(\"field: ", string(field.Desc.Name()), " in object: ", string(field.Parent.Desc.Name()), " check value str not match failed\")")
@@ -1197,17 +1197,17 @@ func messagecheck(prefix string, field *protogen.Field, g *protogen.GeneratedFil
1197
1197
g .P ("if v==nil{" )
1198
1198
g .P ("continue" )
1199
1199
g .P ("}" )
1200
- //g.P("if !_", service.GoName, "RpcCheckers [", strconv.Quote(message.GoIdent.String()), "](v){")
1200
+ //g.P("if !_", service.GoName, "WebCheckers [", strconv.Quote(message.GoIdent.String()), "](v){")
1201
1201
//g.P("return false")
1202
- g .P ("if s:=_" , service .GoName , "RpcCheckers [" , strconv .Quote (field .Message .GoIdent .String ()), "](v);s!=\" \" {" )
1202
+ g .P ("if s:=_" , service .GoName , "WebCheckers [" , strconv .Quote (field .Message .GoIdent .String ()), "](v);s!=\" \" {" )
1203
1203
g .P ("return s" )
1204
1204
g .P ("}" )
1205
1205
g .P ("}" )
1206
1206
} else {
1207
1207
g .P ("if " , prefix + field .GoName , "!=nil{" )
1208
- //g.P("if !_", service.GoName, "RpcCheckers [", strconv.Quote(message.GoIdent.String()), "](", prefix+field.GoName, "){")
1208
+ //g.P("if !_", service.GoName, "WebCheckers [", strconv.Quote(message.GoIdent.String()), "](", prefix+field.GoName, "){")
1209
1209
//g.P("return false")
1210
- g .P ("if s:=_" , service .GoName , "RpcCheckers [" , strconv .Quote (field .Message .GoIdent .String ()), "](" , prefix + field .GoName , ");s!=\" \" {" )
1210
+ g .P ("if s:=_" , service .GoName , "WebCheckers [" , strconv .Quote (field .Message .GoIdent .String ()), "](" , prefix + field .GoName , ");s!=\" \" {" )
1211
1211
g .P ("return s" )
1212
1212
g .P ("}" )
1213
1213
g .P ("}" )
@@ -1497,7 +1497,7 @@ func mapcheck(prefix string, field *protogen.Field, fop *descriptorpb.FieldOptio
1497
1497
if proto .HasExtension (fop , pbex .E_MapKeyStringRegMatch ) {
1498
1498
keymatch := proto .GetExtension (fop , pbex .E_MapKeyStringRegMatch ).([]string )
1499
1499
for _ , v := range keymatch {
1500
- g .P ("if !_" , service .GoName , "RpcRegs [" , strconv .Quote (v ), "].MatchString(k){" )
1500
+ g .P ("if !_" , service .GoName , "WebRegs [" , strconv .Quote (v ), "].MatchString(k){" )
1501
1501
g .P ("return \" field: " , string (field .Desc .Name ()), " in object: " , string (field .Parent .Desc .Name ()), " check map key str match failed\" " )
1502
1502
//g.P(g.QualifiedGoIdent(logPackage.Ident("Error")), "(\"field: ", string(field.Desc.Name()), " in object: ", string(field.Parent.Desc.Name()), " check map key str match failed\")")
1503
1503
//g.P("return false")
@@ -1507,7 +1507,7 @@ func mapcheck(prefix string, field *protogen.Field, fop *descriptorpb.FieldOptio
1507
1507
if proto .HasExtension (fop , pbex .E_MapKeyStringRegNotMatch ) {
1508
1508
keynotmatch := proto .GetExtension (fop , pbex .E_MapKeyStringRegNotMatch ).([]string )
1509
1509
for _ , v := range keynotmatch {
1510
- g .P ("if _" , service .GoName , "RpcRegs [" , strconv .Quote (v ), "].MatchString(k){" )
1510
+ g .P ("if _" , service .GoName , "WebRegs [" , strconv .Quote (v ), "].MatchString(k){" )
1511
1511
g .P ("return \" field: " , string (field .Desc .Name ()), " in object: " , string (field .Parent .Desc .Name ()), " check map key str not match failed\" " )
1512
1512
//g.P(g.QualifiedGoIdent(logPackage.Ident("Error")), "(\"field: ", string(field.Desc.Name()), " in object: ", string(field.Parent.Desc.Name()), " check map key str not match failed\")")
1513
1513
//g.P("return false")
@@ -1794,9 +1794,9 @@ func mapcheck(prefix string, field *protogen.Field, fop *descriptorpb.FieldOptio
1794
1794
valmatch := proto .GetExtension (fop , pbex .E_MapValueStringBytesRegMatch ).([]string )
1795
1795
for _ , v := range valmatch {
1796
1796
if isbyteslice {
1797
- g .P ("if !_" , service .GoName , "RpcRegs [" , strconv .Quote (v ), "].Match(v){" )
1797
+ g .P ("if !_" , service .GoName , "WebRegs [" , strconv .Quote (v ), "].Match(v){" )
1798
1798
} else {
1799
- g .P ("if !_" , service .GoName , "RpcRegs [" , strconv .Quote (v ), "].MatchString(v){" )
1799
+ g .P ("if !_" , service .GoName , "WebRegs [" , strconv .Quote (v ), "].MatchString(v){" )
1800
1800
}
1801
1801
g .P ("return \" field: " , string (field .Desc .Name ()), " in object: " , string (field .Parent .Desc .Name ()), " check map value str match failed\" " )
1802
1802
//g.P(g.QualifiedGoIdent(logPackage.Ident("Error")), "(\"field: ", string(field.Desc.Name()), " in object: ", string(field.Parent.Desc.Name()), " check map value str match failed\")")
@@ -1808,9 +1808,9 @@ func mapcheck(prefix string, field *protogen.Field, fop *descriptorpb.FieldOptio
1808
1808
valnotmatch := proto .GetExtension (fop , pbex .E_MapValueStringBytesRegNotMatch ).([]string )
1809
1809
for _ , v := range valnotmatch {
1810
1810
if isbyteslice {
1811
- g .P ("if _" , service .GoName , "RpcRegs [" , strconv .Quote (v ), "].Match(v){" )
1811
+ g .P ("if _" , service .GoName , "WebRegs [" , strconv .Quote (v ), "].Match(v){" )
1812
1812
} else {
1813
- g .P ("if _" , service .GoName , "RpcRegs [" , strconv .Quote (v ), "].MatchString(v){" )
1813
+ g .P ("if _" , service .GoName , "WebRegs [" , strconv .Quote (v ), "].MatchString(v){" )
1814
1814
}
1815
1815
g .P ("return \" field: " , string (field .Desc .Name ()), " in object: " , string (field .Parent .Desc .Name ()), " check map value str not match failed\" " )
1816
1816
//g.P(g.QualifiedGoIdent(logPackage.Ident("Error")), "(\"field: ", string(field.Desc.Name()), " in object: ", string(field.Parent.Desc.Name()), " check map value str not match failed\")")
@@ -1871,9 +1871,9 @@ func mapcheck(prefix string, field *protogen.Field, fop *descriptorpb.FieldOptio
1871
1871
g .P ("if v==nil{" )
1872
1872
g .P ("continue" )
1873
1873
g .P ("}" )
1874
- g .P ("if s:=_" , service .GoName , "RpcCheckers [" , strconv .Quote (val .Message .GoIdent .String ()), "](v);s!=\" \" {" )
1874
+ g .P ("if s:=_" , service .GoName , "WebCheckers [" , strconv .Quote (val .Message .GoIdent .String ()), "](v);s!=\" \" {" )
1875
1875
g .P ("return s" )
1876
- //g.P("if !_", service.GoName, "RpcCheckers [", strconv.Quote(val.Message.GoIdent.String()), "](v){")
1876
+ //g.P("if !_", service.GoName, "WebCheckers [", strconv.Quote(val.Message.GoIdent.String()), "](v){")
1877
1877
//g.P("return false")
1878
1878
g .P ("}" )
1879
1879
}
@@ -1945,31 +1945,31 @@ func genServer(file *protogen.File, g *protogen.GeneratedFile) {
1945
1945
g .P ("if " , g .QualifiedGoIdent (stringsPackage .Ident ("HasPrefix" )), "(ctx.GetContentType()," , strconv .Quote ("application/json" ), "){" )
1946
1946
g .P ("data,e:=ctx.GetBody()" )
1947
1947
g .P ("if e!=nil{" )
1948
- g .P ("ctx.AbortString (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), ",e.Error() )" )
1948
+ g .P ("ctx.Abort (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), ",e)" )
1949
1949
g .P ("return" )
1950
1950
g .P ("}" )
1951
1951
g .P ("if len(data)>0{" )
1952
1952
g .P ("e:=" , g .QualifiedGoIdent (protojsonPackage .Ident ("UnmarshalOptions{DiscardUnknown: true}" )), ".Unmarshal(data,req)" )
1953
1953
g .P ("if e!=nil{" )
1954
- g .P ("ctx.AbortString (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ".String() )" )
1954
+ g .P ("ctx.Abort (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ")" )
1955
1955
g .P ("return" )
1956
1956
g .P ("}" )
1957
1957
g .P ("}" )
1958
1958
g .P ("}else if " , g .QualifiedGoIdent (stringsPackage .Ident ("HasPrefix" )), "(ctx.GetContentType()," , strconv .Quote ("application/x-protobuf" ), "){" )
1959
1959
g .P ("data,e:=ctx.GetBody()" )
1960
1960
g .P ("if e!=nil{" )
1961
- g .P ("ctx.AbortString (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), ",e.Error() )" )
1961
+ g .P ("ctx.Abort (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), ",e)" )
1962
1962
g .P ("return" )
1963
1963
g .P ("}" )
1964
1964
g .P ("if len(data)>0{" )
1965
1965
g .P ("if e:=" , g .QualifiedGoIdent (protoPackage .Ident ("Unmarshal" )), "(data,req);e!=nil{" )
1966
- g .P ("ctx.AbortString (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ".String() )" )
1966
+ g .P ("ctx.Abort (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ")" )
1967
1967
g .P ("return" )
1968
1968
g .P ("}" )
1969
1969
g .P ("}" )
1970
1970
g .P ("}else{" )
1971
1971
g .P ("if e:=ctx.ParseForm();e!=nil{" )
1972
- g .P ("ctx.AbortString (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ".String() )" )
1972
+ g .P ("ctx.Abort (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ")" )
1973
1973
g .P ("return" )
1974
1974
g .P ("}" )
1975
1975
g .P ("data:=" , g .QualifiedGoIdent (bufpoolPackage .Ident ("GetBuffer()" )))
@@ -2057,7 +2057,7 @@ func genServer(file *protogen.File, g *protogen.GeneratedFile) {
2057
2057
g .P ("if data.Len()>2{" )
2058
2058
g .P ("e:=" , g .QualifiedGoIdent (protojsonPackage .Ident ("UnmarshalOptions{DiscardUnknown: true}" )), ".Unmarshal(data.Bytes(),req)" )
2059
2059
g .P ("if e!=nil{" )
2060
- g .P ("ctx.AbortString (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ".String() )" )
2060
+ g .P ("ctx.Abort (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ")" )
2061
2061
g .P ("return" )
2062
2062
g .P ("}" )
2063
2063
g .P ("}" )
@@ -2069,17 +2069,17 @@ func genServer(file *protogen.File, g *protogen.GeneratedFile) {
2069
2069
//g.P("if !_", service.GoName, "WebCheckers[", strconv.Quote(method.Input.GoIdent.String()), "](req){")
2070
2070
g .P ("if s:=_" , service .GoName , "WebCheckers[" , strconv .Quote (method .Input .GoIdent .String ()), "](req);s!=\" \" {" )
2071
2071
g .P (g .QualifiedGoIdent (logPackage .Ident ("Error" )), "(\" [" , pathurl , "]\" ,s)" )
2072
- g .P ("ctx.AbortString (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ".String() )" )
2072
+ g .P ("ctx.Abort (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), "," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), ")" )
2073
2073
g .P ("return" )
2074
2074
g .P ("}" )
2075
2075
}
2076
2076
2077
2077
g .P ("resp,e:=handler(ctx,req)" )
2078
2078
g .P ("if e!=nil{" )
2079
2079
g .P ("if " , g .QualifiedGoIdent (errorPackage .Ident ("Equal" )), "(e," , g .QualifiedGoIdent (errorPackage .Ident ("ErrReq" )), "){" )
2080
- g .P ("ctx.AbortString (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), ",e.Error() )" )
2080
+ g .P ("ctx.Abort (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusBadRequest" )), ",e)" )
2081
2081
g .P ("}else{" )
2082
- g .P ("ctx.AbortString (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusInternalServerError" )), ",e.Error() )" )
2082
+ g .P ("ctx.Abort (" , g .QualifiedGoIdent (httpPackage .Ident ("StatusInternalServerError" )), ",e)" )
2083
2083
g .P ("}" )
2084
2084
g .P ("return" )
2085
2085
g .P ("}" )
0 commit comments