Skip to content

Commit

Permalink
Merge pull request #389 from cloudwego/release/v0.4.1
Browse files Browse the repository at this point in the history
chore: release v0.4.1
  • Loading branch information
welkeyever committed Nov 18, 2022
2 parents 8864a2a + 3cc775a commit ec22b5a
Show file tree
Hide file tree
Showing 115 changed files with 1,739 additions and 346 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode
pkg/app/fs.go.hertz.gz
coverage.out
coverage.out
2 changes: 1 addition & 1 deletion .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ header:

paths-ignore:
- pkg/common/testdata/**
- cmd/hz/internal/protobuf/api
- cmd/hz/protobuf/api

comment: on-failure
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Hertz [həːts] is a high-usability, high-performance and high-extensibility Gol

Comparison of four frameworks:
![Performance](images/performance-4.png)
Latency comparison of three frameworks:
Comparison of three frameworks:
![Performance](images/performance-3.png)
For detailed performance data, please refer to [hertz-benchmark](https://github.com/cloudwego/hertz-benchmark).
- High extensibility
Expand Down Expand Up @@ -64,7 +64,7 @@ Hertz [həːts] is a high-usability, high-performance and high-extensibility Gol
| [Pprof](https://github.com/hertz-contrib/pprof) | Extension for Hertz integration with Pprof. |
| [Sessions](https://github.com/hertz-contrib/sessions) | Session middleware with multi-state store support. |
| [Obs-opentelemetry](https://github.com/hertz-contrib/obs-opentelemetry) | Hertz's Opentelemetry extension that supports Metric, Logger, Tracing and works out of the box. |
| [Registry](https://github.com/hertz-contrib/registry) | Provides service registry and discovery functions. So far, the supported service discovery extensions are nacos, consul, etcd, eureka, polaris, servicecomb, zookeeper. |
| [Registry](https://github.com/hertz-contrib/registry) | Provides service registry and discovery functions. So far, the supported service discovery extensions are nacos, consul, etcd, eureka, polaris, servicecomb, zookeeper, redis. |
| [Keyauth](https://github.com/hertz-contrib/keyauth) | Provides token-based authentication. |
| [Secure](https://github.com/hertz-contrib/secure) | Secure middleware with multiple configuration items. |
| [Sentry](https://github.com/hertz-contrib/hertzsentry) | Sentry extension provides some unified interfaces to help users perform real-time error monitoring. |
Expand All @@ -83,9 +83,14 @@ Hertz [həːts] is a high-usability, high-performance and high-extensibility Gol
| [Recovery](https://github.com/cloudwego/hertz/tree/develop/pkg/app/middlewares/server/recovery) | Recovery middleware for Hertz. |
| [Basicauth](https://github.com/cloudwego/hertz/tree/develop/pkg/app/middlewares/server/basic_auth) | Basicauth middleware can provide HTTP basic authentication. |
| [Lark](https://github.com/hertz-contrib/lark-hertz) | Use hertz handle Lark/Feishu card message and event callback. |
| [Logger](https://github.com/hertz-contrib/logger) | Logger extension for Hertz, which provides support for zap, logrus, zerologs logging frameworks. |

## Blogs
- [ByteDance Practice on Go Network Library](https://www.cloudwego.io/blog/2021/10/09/bytedance-practices-on-go-network-library/)
- [Ultra-large-scale Enterprise-level Microservice HTTP Framework — Hertz is Officially Open Source!](https://www.cloudwego.io/zh/blog/2022/06/21/%E8%B6%85%E5%A4%A7%E8%A7%84%E6%A8%A1%E7%9A%84%E4%BC%81%E4%B8%9A%E7%BA%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1-http-%E6%A1%86%E6%9E%B6-hertz-%E6%AD%A3%E5%BC%8F%E5%BC%80%E6%BA%90/)
- [ByteDance Open Source Go HTTP Framework Hertz Design Practice](https://www.cloudwego.io/zh/blog/2022/06/21/%E5%AD%97%E8%8A%82%E8%B7%B3%E5%8A%A8%E5%BC%80%E6%BA%90-go-http-%E6%A1%86%E6%9E%B6-hertz-%E8%AE%BE%E8%AE%A1%E5%AE%9E%E8%B7%B5/)
- [Help ByteDance Reduce Costs and Increase Efficiency, the Design Practice for Large-scale Enterprise-level HTTP Framework Hertz](https://www.cloudwego.io/zh/blog/2022/09/27/%E5%8A%A9%E5%8A%9B%E5%AD%97%E8%8A%82%E9%99%8D%E6%9C%AC%E5%A2%9E%E6%95%88%E5%A4%A7%E8%A7%84%E6%A8%A1%E4%BC%81%E4%B8%9A%E7%BA%A7-http-%E6%A1%86%E6%9E%B6-hertz-%E8%AE%BE%E8%AE%A1%E5%AE%9E%E8%B7%B5/)
- [A Practical Introduction to the HTTP Framework Hertz: A Guide to Performance Testing](https://www.cloudwego.io/zh/blog/2022/11/01/http-%E6%A1%86%E6%9E%B6-hertz-%E5%AE%9E%E8%B7%B5%E5%85%A5%E9%97%A8%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95%E6%8C%87%E5%8D%97/)
## Contributing

[Contributing](https://github.com/cloudwego/hertz/blob/main/CONTRIBUTING.md)
Expand All @@ -97,12 +102,17 @@ Hertz is distributed under the [Apache License, version 2.0](https://github.com/
- Email: [[email protected]]([email protected])
- How to become a member: [COMMUNITY MEMBERSHIP](https://github.com/cloudwego/community/blob/main/COMMUNITY_MEMBERSHIP.md)
- Issues: [Issues](https://github.com/cloudwego/hertz/issues)
- Slack: Join our CloudWeGo community [Slack Channel](https://join.slack.com/t/cloudwego/shared_invite/zt-tmcbzewn-UjXMF3ZQsPhl7W3tEDZboA).
- 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!

[![Contributors](https://contrib.rocks/image?repo=cloudwego/hertz)](https://github.com/cloudwego/hertz/graphs/contributors)
## Landscapes

<p align="center">
Expand Down
14 changes: 12 additions & 2 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Hertz[həːts] 是一个 Golang 微服务 HTTP 框架,在设计之初参考了

四个框架的对比:
![Performance](images/performance-4.png)
三个框架的时延对比:
三个框架的对比:
![Performance](images/performance-3.png)
关于详细的性能数据,可参考 [hertz-benchmark](https://github.com/cloudwego/hertz-benchmark)
- 高扩展性
Expand Down Expand Up @@ -64,7 +64,7 @@ Hertz[həːts] 是一个 Golang 微服务 HTTP 框架,在设计之初参考了
| [Pprof](https://github.com/hertz-contrib/pprof) | Hertz 集成 Pprof 的扩展。 |
| [Sessions](https://github.com/hertz-contrib/sessions) | 具有多状态存储支持的 Session 中间件。 |
| [Obs-opentelemetry](https://github.com/hertz-contrib/obs-opentelemetry) | Hertz 的 Opentelemetry 扩展,支持 Metric、Logger、Tracing并且达到开箱即用。 |
| [Registry](https://github.com/hertz-contrib/registry) | 提供服务注册与发现功能。到现在为止,支持的服务发现拓展有 nacos, consul, etcd, eureka, polaris, servicecomb, zookeeper。 |
| [Registry](https://github.com/hertz-contrib/registry) | 提供服务注册与发现功能。到现在为止,支持的服务发现拓展有 nacos, consul, etcd, eureka, polaris, servicecomb, zookeeper, redis|
| [Keyauth](https://github.com/hertz-contrib/keyauth) | 提供基于 token 的身份验证。 |
| [Secure](https://github.com/hertz-contrib/secure) | 具有多配置项的 Secure 中间件。 |
| [Sentry](https://github.com/hertz-contrib/hertzsentry) | Sentry 拓展提供了一些统一的接口来帮助用户进行实时的错误监控。 |
Expand All @@ -83,9 +83,14 @@ Hertz[həːts] 是一个 Golang 微服务 HTTP 框架,在设计之初参考了
| [Recovery](https://github.com/cloudwego/hertz/tree/develop/pkg/app/middlewares/server/recovery) | Hertz 的异常恢复中间件。 |
| [Basicauth](https://github.com/cloudwego/hertz/tree/develop/pkg/app/middlewares/server/basic_auth) | Basicauth 中间件能够提供 HTTP 基本身份验证。 |
| [Lark](https://github.com/hertz-contrib/lark-hertz) | 在 Hertz 中处理 Lark/飞书的卡片消息和事件的回调。 |
| [Logger](https://github.com/hertz-contrib/logger) | Hertz 的日志拓展,提供了对 zap、logrus、zerologs 日志框架的支持。 |

## 相关文章
- [字节跳动在 Go 网络库上的实践](https://www.cloudwego.io/blog/2021/10/09/bytedance-practices-on-go-network-library/)
- [超大规模的企业级微服务 HTTP 框架 — Hertz 正式开源!](https://www.cloudwego.io/zh/blog/2022/06/21/%E8%B6%85%E5%A4%A7%E8%A7%84%E6%A8%A1%E7%9A%84%E4%BC%81%E4%B8%9A%E7%BA%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1-http-%E6%A1%86%E6%9E%B6-hertz-%E6%AD%A3%E5%BC%8F%E5%BC%80%E6%BA%90/)
- [字节跳动开源 Go HTTP 框架 Hertz 设计实践](https://www.cloudwego.io/zh/blog/2022/06/21/%E5%AD%97%E8%8A%82%E8%B7%B3%E5%8A%A8%E5%BC%80%E6%BA%90-go-http-%E6%A1%86%E6%9E%B6-hertz-%E8%AE%BE%E8%AE%A1%E5%AE%9E%E8%B7%B5/)
- [助力字节降本增效,大规模企业级 HTTP 框架 Hertz 设计实践](https://www.cloudwego.io/zh/blog/2022/09/27/%E5%8A%A9%E5%8A%9B%E5%AD%97%E8%8A%82%E9%99%8D%E6%9C%AC%E5%A2%9E%E6%95%88%E5%A4%A7%E8%A7%84%E6%A8%A1%E4%BC%81%E4%B8%9A%E7%BA%A7-http-%E6%A1%86%E6%9E%B6-hertz-%E8%AE%BE%E8%AE%A1%E5%AE%9E%E8%B7%B5/)
- [HTTP 框架 Hertz 实践入门:性能测试指南](https://www.cloudwego.io/zh/blog/2022/11/01/http-%E6%A1%86%E6%9E%B6-hertz-%E5%AE%9E%E8%B7%B5%E5%85%A5%E9%97%A8%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95%E6%8C%87%E5%8D%97/)
## 贡献代码
[Contributing](https://github.com/cloudwego/hertz/blob/main/CONTRIBUTING.md)
## RoadMap
Expand All @@ -98,12 +103,17 @@ Hertz 基于[Apache License 2.0](https://github.com/cloudwego/hertz/blob/main/LI
- Email: [email protected]
- 如何成为 member: [COMMUNITY MEMBERSHIP](https://github.com/cloudwego/community/blob/main/COMMUNITY_MEMBERSHIP.md)
- Issues: [Issues](https://github.com/cloudwego/hertz/issues)
- Slack: 加入我们的 [Slack 频道](https://join.slack.com/t/cloudwego/shared_invite/zt-tmcbzewn-UjXMF3ZQsPhl7W3tEDZboA)
- 飞书用户群([注册飞书](https://www.larksuite.com/zh_cn/download)进群)

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

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

[![Contributors](https://contrib.rocks/image?repo=cloudwego/hertz)](https://github.com/cloudwego/hertz/graphs/contributors)
## Landscapes

<p align="center">
Expand Down
91 changes: 81 additions & 10 deletions cmd/hz/internal/app/app.go → cmd/hz/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ package app
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/cloudwego/hertz/cmd/hz/internal/config"
"github.com/cloudwego/hertz/cmd/hz/internal/generator"
"github.com/cloudwego/hertz/cmd/hz/internal/meta"
"github.com/cloudwego/hertz/cmd/hz/internal/util"
"github.com/cloudwego/hertz/cmd/hz/internal/util/logs"
"github.com/cloudwego/hertz/cmd/hz/config"
"github.com/cloudwego/hertz/cmd/hz/generator"
"github.com/cloudwego/hertz/cmd/hz/meta"
"github.com/cloudwego/hertz/cmd/hz/protobuf"
"github.com/cloudwego/hertz/cmd/hz/thrift"
"github.com/cloudwego/hertz/cmd/hz/util"
"github.com/cloudwego/hertz/cmd/hz/util/logs"
"github.com/urfave/cli/v2"
)

Expand All @@ -40,12 +44,12 @@ func New(c *cli.Context) error {
setLogVerbose(args.Verbose)
logs.Debugf("args: %#v\n", args)

err = generateLayout(args)
err = GenerateLayout(args)
if err != nil {
return cli.Exit(err, meta.GenerateLayoutError)
}

err = triggerPlugin(args)
err = TriggerPlugin(args)
if err != nil {
return cli.Exit(err, meta.PluginError)
}
Expand All @@ -67,7 +71,7 @@ func Update(c *cli.Context) error {
setLogVerbose(args.Verbose)
logs.Debugf("Args: %#v\n", args)

err = triggerPlugin(args)
err = TriggerPlugin(args)
if err != nil {
return cli.Exit(err, meta.PluginError)
}
Expand All @@ -80,6 +84,37 @@ func Update(c *cli.Context) error {
return nil
}

func Model(c *cli.Context) error {
args, err := globalArgs.Parse(c, meta.CmdModel)
if err != nil {
return cli.Exit(err, meta.LoadError)
}
setLogVerbose(args.Verbose)
logs.Debugf("Args: %#v\n", args)

err = TriggerPlugin(args)
if err != nil {
return cli.Exit(err, meta.PluginError)
}

return nil
}

func PluginMode() {
pluginName := filepath.Base(os.Args[0])
if util.IsWindows() {
pluginName = strings.TrimSuffix(pluginName, ".exe")
}
switch pluginName {
case meta.ThriftPluginName:
plugin := new(thrift.Plugin)
os.Exit(plugin.Run())
case meta.ProtocPluginName:
plugin := new(protobuf.Plugin)
os.Exit(plugin.Run())
}
}

func Init() *cli.App {
// flags
verboseFlag := cli.BoolFlag{Name: "verbose,vv", Usage: "turn on verbose mode", Destination: &globalArgs.Verbose}
Expand All @@ -97,19 +132,25 @@ func Init() *cli.App {
excludeFilesFlag := cli.StringSliceFlag{Name: "exclude_file", Aliases: []string{"E"}, Usage: "Specify the files that do not need to be updated."}
thriftOptionsFlag := cli.StringSliceFlag{Name: "thriftgo", Aliases: []string{"t"}, Usage: "Specify arguments for the thriftgo. ({flag}={value})"}
protoOptionsFlag := cli.StringSliceFlag{Name: "protoc", Aliases: []string{"p"}, Usage: "Specify arguments for the protoc. ({flag}={value})"}
thriftPluginsFlag := cli.StringSliceFlag{Name: "thrift-plugins", Usage: "Specify plugins for the thriftgo. ({plugin_name}:{options})"}
protoPluginsFlag := cli.StringSliceFlag{Name: "protoc-plugins", Usage: "Specify plugins for the protoc. ({plugin_name}:{options}:{out_dir})"}
noRecurseFlag := cli.BoolFlag{Name: "no_recurse", Usage: "Generate master model only.", Destination: &globalArgs.NoRecurse}

jsonEnumStrFlag := cli.BoolFlag{Name: "json_enumstr", Usage: "Use string instead of num for json enums when idl is thrift.", Destination: &globalArgs.JSONEnumStr}
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}
customLayout := cli.StringFlag{Name: "customize_layout", Usage: "Specify the layout template. ({{Template Profile}}:{{Rendering Data}})", Destination: &globalArgs.CustomizeLayout}
customPackage := cli.StringFlag{Name: "customize_package", Usage: "Specify the package template. ({{Template Profile}}:)", Destination: &globalArgs.CustomizePackage}
handlerByMethod := cli.BoolFlag{Name: "handler_by_method", Usage: "Generate a separate handler file for each method.", Destination: &globalArgs.HandlerByMethod}

// app
app := cli.NewApp()
app.Name = "hz"
app.Usage = "A idl parser and code generator for Hertz projects"
app.Version = meta.Version
// The default separator for multiple parameters is modified to ";"
app.SliceFlagSeparator = ";"

// global flags
app.Flags = []cli.Flag{
Expand Down Expand Up @@ -138,10 +179,14 @@ func Init() *cli.App {

&jsonEnumStrFlag,
&unsetOmitemptyFlag,
&protoCamelJSONTag,
&snakeNameFlag,
&excludeFilesFlag,
&customLayout,
&customPackage,
&handlerByMethod,
&protoPluginsFlag,
&thriftPluginsFlag,
},
Action: New,
},
Expand All @@ -163,12 +208,38 @@ func Init() *cli.App {

&jsonEnumStrFlag,
&unsetOmitemptyFlag,
&protoCamelJSONTag,
&snakeNameFlag,
&excludeFilesFlag,
&customPackage,
&handlerByMethod,
&protoPluginsFlag,
&thriftPluginsFlag,
},
Action: Update,
},
{
Name: meta.CmdModel,
Usage: "Generate model code only",
Flags: []cli.Flag{
&idlFlag,
&moduleFlag,
&outDirFlag,
&modelDirFlag,

&includesFlag,
&thriftOptionsFlag,
&protoOptionsFlag,
&noRecurseFlag,

&jsonEnumStrFlag,
&unsetOmitemptyFlag,
&protoCamelJSONTag,
&snakeNameFlag,
&excludeFilesFlag,
},
Action: Model,
},
}
return app
}
Expand All @@ -181,7 +252,7 @@ func setLogVerbose(verbose bool) {
}
}

func generateLayout(args *config.Argument) error {
func GenerateLayout(args *config.Argument) error {
lg := &generator.LayoutGenerator{
TemplateGenerator: generator.TemplateGenerator{
OutputDir: args.OutDir,
Expand Down Expand Up @@ -240,7 +311,7 @@ func generateLayout(args *config.Argument) error {
return nil
}

func triggerPlugin(args *config.Argument) error {
func TriggerPlugin(args *config.Argument) error {
if len(args.IdlPaths) == 0 {
return nil
}
Expand Down
24 changes: 15 additions & 9 deletions cmd/hz/internal/config/argument.go → cmd/hz/config/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"path/filepath"
"strings"

"github.com/cloudwego/hertz/cmd/hz/internal/meta"
"github.com/cloudwego/hertz/cmd/hz/internal/util"
"github.com/cloudwego/hertz/cmd/hz/meta"
"github.com/cloudwego/hertz/cmd/hz/util"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -51,13 +51,17 @@ type Argument struct {
Gopkg string // $GOPATH/src/{{gopkg}}
ServiceName string // service name

JSONEnumStr bool
UnsetOmitempty bool
ProtocOptions []string // options to pass through to protoc
ThriftOptions []string // options to pass through to thriftgo
SnakeName bool
Excludes []string
NoRecurse bool
JSONEnumStr bool
UnsetOmitempty bool
ProtobufCamelJSONTag bool
ProtocOptions []string // options to pass through to protoc
ThriftOptions []string // options to pass through to thriftgo for go flag
ProtobufPlugins []string
ThriftPlugins []string
SnakeName bool
Excludes []string
NoRecurse bool
HandlerByMethod bool

CustomizeLayout string
CustomizePackage string
Expand Down Expand Up @@ -106,6 +110,8 @@ func (arg *Argument) parseStringSlice(c *cli.Context) {
arg.RawOptPkg = c.StringSlice("option_package")
arg.ThriftOptions = c.StringSlice("thriftgo")
arg.ProtocOptions = c.StringSlice("protoc")
arg.ThriftPlugins = c.StringSlice("thrift-plugins")
arg.ProtobufPlugins = c.StringSlice("protoc-plugins")
}

// checkPath sets the project path and verifies that the model、handler、router and client path is compliant
Expand Down
Loading

0 comments on commit ec22b5a

Please sign in to comment.