Skip to content

Commit

Permalink
chore: release v0.6.7 (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
welkeyever authored Aug 4, 2023
2 parents 752e2a6 + 69c2888 commit 0db9f4f
Show file tree
Hide file tree
Showing 41 changed files with 1,199 additions and 159 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ Hertz is distributed under the [Apache License, version 2.0](https://github.com/
- Lark: Scan the QR code below with [Lark](https://www.larksuite.com/zh_cn/download) to join our CloudWeGo/hertz user group.

![LarkGroup](images/lark_group.png)
- WeChat: CloudWeGo community WeChat group.

![WechatGroup](images/wechat_group_cn.png)
## Contributors
Thank you for your contribution to Hertz!

Expand Down
4 changes: 1 addition & 3 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ Hertz 基于[Apache License 2.0](https://github.com/cloudwego/hertz/blob/main/LI
- 飞书用户群([注册飞书](https://www.larksuite.com/zh_cn/download)进群)

![LarkGroup](images/lark_group_cn.png)
- 微信: CloudWeGo community

![WechatGroup](images/wechat_group_cn.png)
## 贡献者
感谢您对 Hertz 作出的贡献!

Expand All @@ -126,4 +124,4 @@ Hertz 基于[Apache License 2.0](https://github.com/cloudwego/hertz/blob/main/LI
<img src="https://landscape.cncf.io/images/left-logo.svg" width="150"/>&nbsp;&nbsp;<img src="https://landscape.cncf.io/images/right-logo.svg" width="200"/>
<br/><br/>
CloudWeGo 丰富了 <a href="https://landscape.cncf.io/">CNCF 云原生生态</a>。
</p>
</p>
3 changes: 2 additions & 1 deletion _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ referer = "referer"
HeaderReferer = "HeaderReferer"
expectedReferer = "expectedReferer"
Referer = "Referer"
O_WRONLY = "O_WRONLY"
O_WRONLY = "O_WRONLY"
WRONLY = "WRONLY"
5 changes: 5 additions & 0 deletions cmd/hz/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func Init() *cli.App {
unsetOmitemptyFlag := cli.BoolFlag{Name: "unset_omitempty", Usage: "Remove 'omitempty' tag for generated struct.", Destination: &globalArgs.UnsetOmitempty}
protoCamelJSONTag := cli.BoolFlag{Name: "pb_camel_json_tag", Usage: "Convert Name style for json tag to camel(Only works protobuf).", Destination: &globalArgs.ProtobufCamelJSONTag}
snakeNameFlag := cli.BoolFlag{Name: "snake_tag", Usage: "Use snake_case style naming for tags. (Only works for 'form', 'query', 'json')", Destination: &globalArgs.SnakeName}
rmTagFlag := cli.StringSliceFlag{Name: "rm_tag", Usage: "Remove the specified tag"}
customLayout := cli.StringFlag{Name: "customize_layout", Usage: "Specify the path for layout template.", Destination: &globalArgs.CustomizeLayout}
customLayoutData := cli.StringFlag{Name: "customize_layout_data_path", Usage: "Specify the path for layout template render data.", Destination: &globalArgs.CustomizeLayoutData}
customPackage := cli.StringFlag{Name: "customize_package", Usage: "Specify the path for package template.", Destination: &globalArgs.CustomizePackage}
Expand Down Expand Up @@ -230,6 +231,7 @@ func Init() *cli.App {
&unsetOmitemptyFlag,
&protoCamelJSONTag,
&snakeNameFlag,
&rmTagFlag,
&excludeFilesFlag,
&customLayout,
&customLayoutData,
Expand Down Expand Up @@ -263,6 +265,7 @@ func Init() *cli.App {
&unsetOmitemptyFlag,
&protoCamelJSONTag,
&snakeNameFlag,
&rmTagFlag,
&excludeFilesFlag,
&customPackage,
&handlerByMethod,
Expand All @@ -289,6 +292,7 @@ func Init() *cli.App {
&unsetOmitemptyFlag,
&protoCamelJSONTag,
&snakeNameFlag,
&rmTagFlag,
&excludeFilesFlag,
},
Action: Model,
Expand All @@ -315,6 +319,7 @@ func Init() *cli.App {
&unsetOmitemptyFlag,
&protoCamelJSONTag,
&snakeNameFlag,
&rmTagFlag,
&excludeFilesFlag,
&customLayout,
&customLayoutData,
Expand Down
2 changes: 2 additions & 0 deletions cmd/hz/config/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Argument struct {
ProtobufPlugins []string
ThriftPlugins []string
SnakeName bool
RmTags []string
Excludes []string
NoRecurse bool
HandlerByMethod bool
Expand Down Expand Up @@ -121,6 +122,7 @@ func (arg *Argument) parseStringSlice(c *cli.Context) {
arg.ProtocOptions = c.StringSlice("protoc")
arg.ThriftPlugins = c.StringSlice("thrift-plugins")
arg.ProtobufPlugins = c.StringSlice("protoc-plugins")
arg.RmTags = c.StringSlice("rm_tag")
}

func (arg *Argument) UpdateByManifest(m *meta.Manifest) {
Expand Down
49 changes: 27 additions & 22 deletions cmd/hz/generator/custom_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ type IDLPackageRenderInfo struct {

type CustomizedFileForMethod struct {
*HttpMethod
FilePath string
FilePackage string
ServiceInfo *Service // service info for that method
FilePath string
FilePackage string
ServiceInfo *Service // service info for this method
IDLPackageInfo *IDLPackageRenderInfo // IDL info for this service
}

type CustomizedFileForService struct {
*Service
FilePath string
FilePackage string
IDLPackageInfo *IDLPackageRenderInfo // IDL info for that service
IDLPackageInfo *IDLPackageRenderInfo // IDL info for this service
}

type CustomizedFileForIDL struct {
Expand Down Expand Up @@ -110,7 +111,7 @@ func (pkgGen *HttpPackageGenerator) genCustomizedFile(pkg *HttpPackage) error {
filePathRenderInfo.ServiceName = service.Name
filePathRenderInfo.MethodName = method.Name
filePathRenderInfo.HandlerGenPath = method.OutputDir
err := pkgGen.genLoopMethod(tplInfo, filePathRenderInfo, method, service)
err := pkgGen.genLoopMethod(tplInfo, filePathRenderInfo, method, service, &idlPackageRenderInfo)
if err != nil {
return err
}
Expand Down Expand Up @@ -323,10 +324,11 @@ func (pkgGen *HttpPackageGenerator) genLoopService(tplInfo *Template, filePathRe
if tplInfo.UpdateBehavior.AppendKey == "method" {
for _, method := range service.Methods {
data := CustomizedFileForMethod{
HttpMethod: method,
FilePath: filePath,
FilePackage: util.SplitPackage(filepath.Dir(filePath), ""),
ServiceInfo: service,
HttpMethod: method,
FilePath: filePath,
FilePackage: util.SplitPackage(filepath.Dir(filePath), ""),
ServiceInfo: service,
IDLPackageInfo: idlPackageRenderInfo,
}
insertKey, err := renderInsertKey(tplInfo, data)
if err != nil {
Expand Down Expand Up @@ -395,7 +397,7 @@ func (pkgGen *HttpPackageGenerator) genLoopService(tplInfo *Template, filePathRe
}

// genLoopMethod used to generate files by 'method'
func (pkgGen *HttpPackageGenerator) genLoopMethod(tplInfo *Template, filePathRenderInfo FilePathRenderInfo, method *HttpMethod, service *Service) error {
func (pkgGen *HttpPackageGenerator) genLoopMethod(tplInfo *Template, filePathRenderInfo FilePathRenderInfo, method *HttpMethod, service *Service, idlPackageRenderInfo *IDLPackageRenderInfo) error {
filePath, err := renderFilePath(tplInfo, filePathRenderInfo)
if err != nil {
return err
Expand All @@ -408,10 +410,11 @@ func (pkgGen *HttpPackageGenerator) genLoopMethod(tplInfo *Template, filePathRen

if !exist { // create file
data := CustomizedFileForMethod{
HttpMethod: method,
FilePath: filePath,
FilePackage: util.SplitPackage(filepath.Dir(filePath), ""),
ServiceInfo: service,
HttpMethod: method,
FilePath: filePath,
FilePackage: util.SplitPackage(filepath.Dir(filePath), ""),
ServiceInfo: service,
IDLPackageInfo: idlPackageRenderInfo,
}
err := pkgGen.TemplateGenerator.Generate(data, tplInfo.Path, filePath, false)
if err != nil {
Expand All @@ -426,10 +429,11 @@ func (pkgGen *HttpPackageGenerator) genLoopMethod(tplInfo *Template, filePathRen
// re-generate
logs.Infof("re-generate file '%s', because the update behavior is 'Regenerate'", filePath)
data := CustomizedFileForMethod{
HttpMethod: method,
FilePath: filePath,
FilePackage: util.SplitPackage(filepath.Dir(filePath), ""),
ServiceInfo: service,
HttpMethod: method,
FilePath: filePath,
FilePackage: util.SplitPackage(filepath.Dir(filePath), ""),
ServiceInfo: service,
IDLPackageInfo: idlPackageRenderInfo,
}
err := pkgGen.TemplateGenerator.Generate(data, tplInfo.Path, filePath, false)
if err != nil {
Expand Down Expand Up @@ -497,10 +501,11 @@ func (pkgGen *HttpPackageGenerator) genSingleCustomizedFile(tplInfo *Template, f
for _, service := range idlPackageRenderInfo.ServiceInfos.Services {
for _, method := range service.Methods {
data := CustomizedFileForMethod{
HttpMethod: method,
FilePath: filePath,
FilePackage: util.SplitPackage(filepath.Dir(filePath), ""),
ServiceInfo: service,
HttpMethod: method,
FilePath: filePath,
FilePackage: util.SplitPackage(filepath.Dir(filePath), ""),
ServiceInfo: service,
IDLPackageInfo: &idlPackageRenderInfo,
}
insertKey, err := renderInsertKey(tplInfo, data)
if err != nil {
Expand Down
26 changes: 15 additions & 11 deletions cmd/hz/generator/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,21 @@ import (
)

type HttpMethod struct {
Name string
HTTPMethod string
Comment string
RequestTypeName string
ReturnTypeName string
Path string
Serializer string
OutputDir string
RefPackage string
RefPackageAlias string
ModelPackage map[string]string
Name string
HTTPMethod string
Comment string
RequestTypeName string
RequestTypePackage string
RequestTypeRawName string
ReturnTypeName string
ReturnTypePackage string
ReturnTypeRawName string
Path string
Serializer string
OutputDir string
RefPackage string // handler import dir
RefPackageAlias string // handler import alias
ModelPackage map[string]string
// Annotations map[string]string
Models map[string]*model.Model
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/hz/generator/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"reflect"
"strings"

"github.com/cloudwego/hertz/cmd/hz/meta"
"github.com/cloudwego/hertz/cmd/hz/util"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -169,10 +170,14 @@ func serviceToLayoutData(service Layout) (map[string]interface{}, error) {
if len(service.RouterDir) != 0 {
routerPkg = filepath.Base(service.RouterDir)
}
serviceName := service.ServiceName
if len(serviceName) == 0 {
serviceName = meta.DefaultServiceName
}

return map[string]interface{}{
"GoModule": goMod,
"ServiceName": service.ServiceName,
"ServiceName": serviceName,
"UseApacheThrift": service.UseApacheThrift,
"HandlerPkg": handlerPkg,
"RouterPkg": routerPkg,
Expand Down
4 changes: 3 additions & 1 deletion cmd/hz/meta/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package meta
import "runtime"

// Version hz version
const Version = "v0.6.5"
const Version = "v0.6.6"

const DefaultServiceName = "hertz_service"

// Mode hz run modes
type Mode int
Expand Down
10 changes: 10 additions & 0 deletions cmd/hz/protobuf/api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ extend google.protobuf.FieldOptions {
optional string js_conv_compatible = 50132;
optional string file_name_compatible = 50133;
optional string none_compatible = 50134;
// 50135 is reserved to vt_compatible
// optional FieldRules vt_compatible = 50135;

optional string go_tag = 51001;
}
Expand Down Expand Up @@ -62,4 +64,12 @@ extend google.protobuf.ServiceOptions {

// 50731~50760 used to extend service option by hz
optional string base_domain_compatible = 50731;
}

extend google.protobuf.MessageOptions {
// optional FieldRules msg_vt = 50111;

optional string reserve = 50830;
// 550831 is reserved to msg_vt_compatible
// optional FieldRules msg_vt_compatible = 50831;
}
24 changes: 16 additions & 8 deletions cmd/hz/protobuf/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,20 @@ func astToService(ast *descriptorpb.FileDescriptorProto, resolver *Resolver, cmd

reqName := m.GetInputType()
sb, err := resolver.ResolveIdentifier(reqName)
reqName = util.BaseName(sb.Scope.GetOptions().GetGoPackage(), "") + "." + inputGoType.GoIdent.GoName
if err != nil {
return nil, err
}
reqName = util.BaseName(sb.Scope.GetOptions().GetGoPackage(), "") + "." + inputGoType.GoIdent.GoName
reqRawName := inputGoType.GoIdent.GoName
reqPackage := util.BaseName(sb.Scope.GetOptions().GetGoPackage(), "")
respName := m.GetOutputType()
st, err := resolver.ResolveIdentifier(respName)
respName = util.BaseName(st.Scope.GetOptions().GetGoPackage(), "") + "." + outputGoType.GoIdent.GoName
if err != nil {
return nil, err
}
respName = util.BaseName(st.Scope.GetOptions().GetGoPackage(), "") + "." + outputGoType.GoIdent.GoName
respRawName := outputGoType.GoIdent.GoName
respPackage := util.BaseName(sb.Scope.GetOptions().GetGoPackage(), "")

var serializer string
sl, sv := checkFirstOptions(SerializerOptions, m.GetOptions())
Expand Down Expand Up @@ -212,7 +216,11 @@ func astToService(ast *descriptorpb.FileDescriptorProto, resolver *Resolver, cmd
respName = goOptMapAlias[st.Scope.GetOptions().GetGoPackage()] + "." + outputGoType.GoIdent.GoName
}
method.RequestTypeName = reqName
method.RequestTypeRawName = reqRawName
method.RequestTypePackage = reqPackage
method.ReturnTypeName = respName
method.ReturnTypeRawName = respRawName
method.ReturnTypePackage = respPackage

methods = append(methods, method)

Expand Down Expand Up @@ -269,14 +277,14 @@ func parseAnnotationToClient(clientMethod *generator.ClientMethod, gen *protogen
if proto.HasExtension(f.Desc.Options(), api.E_Query) {
hasAnnotation = true
queryAnnos := proto.GetExtension(f.Desc.Options(), api.E_Query)
val := queryAnnos.(string)
val := checkSnakeName(queryAnnos.(string))
clientMethod.QueryParamsCode += fmt.Sprintf("%q: req.Get%s(),\n", val, f.GoName)
}

if proto.HasExtension(f.Desc.Options(), api.E_Path) {
hasAnnotation = true
pathAnnos := proto.GetExtension(f.Desc.Options(), api.E_Path)
val := pathAnnos.(string)
val := checkSnakeName(pathAnnos.(string))
if isStringFieldType {
clientMethod.PathParamsCode += fmt.Sprintf("%q: req.Get%s(),\n", val, f.GoName)
} else {
Expand All @@ -287,7 +295,7 @@ func parseAnnotationToClient(clientMethod *generator.ClientMethod, gen *protogen
if proto.HasExtension(f.Desc.Options(), api.E_Header) {
hasAnnotation = true
headerAnnos := proto.GetExtension(f.Desc.Options(), api.E_Header)
val := headerAnnos.(string)
val := checkSnakeName(headerAnnos.(string))
if isStringFieldType {
clientMethod.HeaderParamsCode += fmt.Sprintf("%q: req.Get%s(),\n", val, f.GoName)
} else {
Expand All @@ -298,7 +306,7 @@ func parseAnnotationToClient(clientMethod *generator.ClientMethod, gen *protogen
if formAnnos := getCompatibleAnnotation(f.Desc.Options(), api.E_Form, api.E_FormCompatible); formAnnos != nil {
hasAnnotation = true
hasFormAnnotation = true
val := formAnnos.(string)
val := checkSnakeName(formAnnos.(string))
if isStringFieldType {
clientMethod.FormValueCode += fmt.Sprintf("%q: req.Get%s(),\n", val, f.GoName)
} else {
Expand All @@ -314,11 +322,11 @@ func parseAnnotationToClient(clientMethod *generator.ClientMethod, gen *protogen
if fileAnnos := getCompatibleAnnotation(f.Desc.Options(), api.E_FileName, api.E_FileNameCompatible); fileAnnos != nil {
hasAnnotation = true
hasFormAnnotation = true
val := fileAnnos.(string)
val := checkSnakeName(fileAnnos.(string))
clientMethod.FormFileCode += fmt.Sprintf("%q: req.Get%s(),\n", val, f.GoName)
}
if !hasAnnotation && strings.EqualFold(clientMethod.HTTPMethod, "get") {
clientMethod.QueryParamsCode += fmt.Sprintf("%q: req.Get%s(),\n", f.GoName, f.GoName)
clientMethod.QueryParamsCode += fmt.Sprintf("%q: req.Get%s(),\n", checkSnakeName(f.GoName), f.GoName)
}
}
clientMethod.BodyParamsCode = meta.SetBodyParam
Expand Down
Loading

0 comments on commit 0db9f4f

Please sign in to comment.