Skip to content

Commit

Permalink
Merge pull request #485 from shuifan/master
Browse files Browse the repository at this point in the history
修正cmd/gobay/README && 修正templates(修复语法错误、补全import、更新lint)
  • Loading branch information
nicholasxuu authored Jun 5, 2023
2 parents 011375c + 7a881da commit 1dbd7d6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cmd/gobay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 生成项目文件夹

```bash
# go get github.com/shanbay/gobay/cmd/gobay
# git clone && go install ./cmd/gobay/
gobay new github.com/shanbay/my_proj
```

Expand All @@ -12,7 +12,7 @@ gobay new github.com/shanbay/my_proj
- openapi 工具: [oapi-codegen](https://github.com/shanbay/oapi-codegen/releases)
- grpc/protobuf 工具: [grpc-go](https://github.com/grpc/grpc-go) [protobuf](https://github.com/golang/protobuf)
- lint 工具: [golangci-lint](https://github.com/golangci/golangci-lint#binary)
- orm 代码生成(ent): [ent](https://github.com/shanbay/ent) 请安装这个版本的 entc `go install entgo.io/ent/cmd/ent@latest`
- orm 代码生成(ent): [ent](https://github.com/shanbay/ent) 请安装这个版本 `go install entgo.io/ent/cmd/ent@version` version与项目内使用的ent版本一致,不然生成可能报错
- gocovmerge: [gocovmerge](https://github.com/wadey/gocovmerge)
- pre-commit: [pre-commit](https://pre-commit.com/#installation)
- gotests: [gotests](https://github.com/cweill/gotests)
Expand Down Expand Up @@ -115,6 +115,6 @@ lint 检查
更新完静态文件(templates 目录),需要将静态文件打包成.go 文件:

```bash
# go get github.com/markbates/pkger/cmd/pkger
# go install github.com/markbates/pkger/cmd/pkger@latest
pkger -include /cmd/gobay/templates -o cmd/gobay/
```
2 changes: 1 addition & 1 deletion cmd/gobay/pkged.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cmd/gobay/templates/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ exclude: "vendor|internal/proto"
repos:
# common
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
# go
- repo: git://github.com/dnephin/pre-commit-golang
rev: v0.3.5
- repo: https://github.com/golangci/golangci-lint
rev: v1.53.0
hooks:
- id: golangci-lint
args: [--fix]
1 change: 1 addition & 0 deletions cmd/gobay/templates/app/oapi/server.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
Expand Down
2 changes: 1 addition & 1 deletion cmd/gobay/templates/cmd/actions/asynctask.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func RunAsyncTaskWorker(cmd *cobra.Command, args []string) {
}
defer bapp.Close()
if err := asynctask.Serve(bapp); err != nil {
log.Fatal("grpc serve failed\n", err)
log.Panicf("grpc serve failed %v\n", err)
}
}

Expand Down
20 changes: 11 additions & 9 deletions cmd/gobay/templates/cmd/actions/health_check.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/credentials/insecure"
)

func checkRPCHealth(service string) {
conn, err := grpc.Dial("127.0.0.1:6000", grpc.WithInsecure(), grpc.WithBlock())
conn, err := grpc.Dial("127.0.0.1:6000", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v\n", err)
}
Expand All @@ -27,10 +28,10 @@ func checkRPCHealth(service string) {
context.Background(),
&grpc_health_v1.HealthCheckRequest{Service: service})
if err != nil {
log.Fatalf("get health heck res failed: %v\n", err)
log.Panicf("get health heck res failed: %v\n", err)
}
if res.Status != grpc_health_v1.HealthCheckResponse_SERVING {
log.Fatalf(" health check response status error: %v\n", res.Status)
log.Panicf(" health check response status error: %v\n", res.Status)
} else {
log.Println("health check response success")
}
Expand All @@ -43,11 +44,11 @@ func checkAPIHealth(service string) {
var resp *http.Response
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalf("did not connect: %v\n", err)
log.Panicf("did not connect: %v\n", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
log.Fatalf("health check response status error: %v\n", resp.Status)
log.Panicf("health check response status error: %v\n", resp.Status)
} else {
log.Println("health check response success")
}
Expand All @@ -59,12 +60,13 @@ func CheckHealth(cmd *cobra.Command, args []string) {
log.Fatalf("get service failed: %v\n", err)
}
SvcType, _ := cmd.Flags().GetString("svc_type")
if SvcType == "httpsvc" {
switch SvcType {
case "httpsvc":
checkAPIHealth(service)
} else if SvcType == "grpcsvc" {
case "grpcsvc":
checkRPCHealth(service)
} else {
log.Fatalln("unknown svc type!")
default:
log.Fatalln("Unknown service type!")
}
}

Expand Down

0 comments on commit 1dbd7d6

Please sign in to comment.