trytry

module
v0.0.0-...-748419f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2023 License: MIT

README

trytry

Putting go-zero into practice locally and personally.

MakeFile

All the related cmds are gathered in the makefile in each of the service. Commands as below if you want to execute them manually.

  1. Basic api file generation
goctl api -o api_dir xxx.api 
  1. Api files import and group
// ./production.outgoing
import (
	"./car/car.outgoing"
	"./brand/brand.outgoing"
)

// ./car/car.outgoing
@server(
   middleware: Authentication, Authorization, Language, RemoteAddr
   group: GROUP
   prefix: PREFIX
)
service production-api {
	@handler Estb
	post /estb(CarEstbReq) returns(CarEstbResp)

	@handler Info
	post /info(CarInfoReq) returns(CarInfoResp)
}
  1. Format
goctl api format --dir .
  1. Code Generation
goctl api go -api ./def/bff.api -dir .

  1. Basic template generation
// .../rpc/pb
goctl rpc -o ./pb/brand.proto
  1. Edit xxx.proto
  2. Code Generation
goctl rpc protoc ./pb/brand.proto --go_out=./pb --go-grpc_out=./pb --zrpc_out=.
// Path: /apps/customer/cmd/rpc/pb
// --go_out 与 --go-grpc_out 生成的最终目录必须一致
// --go_out & --go-grpc_out 和 --zrpc_out 的生成的最终目录必须不为同一目录
goctl rpc protoc xxx.proto --go_out=. --go-grpc_out=. --zrpc_out=../

Middilware
  1. Globle
// global middelware registration at entrance of a single service.
server.Use(func(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logx.Info("--- Globle: Middleware Before")
		next(w, r)
		logx.Info("--- Globle: Middleware After")
	}
})
  1. Local middleware tag will create all the middlewares at apps/service/cmd/api/internal/middleware in seperate files.

    And also, the middleware registration is handled at apps/service/cmd/api/internal/handler/routes.go.

@server(
	middleware: Middle1,Middle2
	...
)
service xxx-api {
	...
}
MySQL
  1. Model Generation
// Path: apps/production
// With: cache, fundamental table, target foler
goctl model mysql datasource --url="user:pwd@tcp(host:port)/db" -table="table" -c -dir=./model_dir --remote="https://github.com/v3nooonn/trytry-template"

PostgreSQL
  1. Model Generation
// Path: apps/production
// With: schema, cache, fundamental table, target foler
 goctl model pg datasource --url="postgres://user:pwd@127.0.0.1:5434/db?sslmode=disable" --schema="schema" -table="table" -c -dir="target" --remote="https://github.com/v3nooonn/trytry-template"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL