garden
go language backend playground
create package
go mod init github.com/stkali/garden
cobra & cobra-cli
install
go get -u github.com/spf13/cobra@latest
go get -u github.com/spf13/cobra-cli@latest
create app structure use cobra and cobra-cli
cobra-cli init -a "<st·kali clarkmonkey@163.com>" -l MIT --viper
cobra-cli add config -a "<st·kali clarkmonkey@163.com>" -l MIT
cobra-cli add server -a "<st·kali clarkmonkey@163.com>" -l MIT
migrate
import golang migration
🏠 golang/migrate
👉 download list
migrate create -ext sql -dir db/migrations -seq desc_table
sqlc
🏠 kyleconroy/sqlc
👉 download list
sqlc generate
📰 sqlc doc
sqlc config file sample
version: 1
packages:
- path: "db/sqlc"
name: "db"
engine: "postgresql"
schema: "db/migration/"
queries: "db/query"
emit_json_tags: true
emit_prepared_queries: false
emit_interface: true
emit_exact_table_names: false
emit_empty_slices: true
genreate go code from sql query
sqlc generate
protoc & gRPC
install proto buffer compiler
🏠 protocolbuffers/protobuf
👉 download list
install Golang plugins for the protocol compiler:
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
Update your PATH so that the protoc compiler can find the plugins:
export PATH="$PATH:$(go env GOPATH)/bin"
# or write it to profile or zshrc file
evans
🏠 ktr0731/evans
👉 download list
evans is a gRPC client
# regsiter reflection
reflection.Register(grpcServer)
connect rpc server
evans -r repl --host <server address> --port <server port>
grpc-gateway
generate http server by protobuf and grpc
🏠 grpc-ecosystem/grpc-gateway
👉 download list
1 copy *.proto to project
// +build tools
package tools
import (
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
)
# pull dependencies
go mod tidy
# install binaries
go install \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
add file to $PROJECT/proto/google/api/*.proto
🏠 googleapis/googleapis
google/api/annotations.proto
google/api/field_behavior.proto
google/api/http.proto
google/api/httpbody.proto