Skip to content

Latest commit

 

History

History
133 lines (105 loc) · 4.55 KB

README.md

File metadata and controls

133 lines (105 loc) · 4.55 KB

protoc-gen-gf

Generate GoFrame business via proto file

Introduction

Workflow

  • Generate the proto file by mysql-to-proto
  • Adjust the services and messages in the proto, please don't use the PATCH method, the generator will generate CRUD for it
  • Generate the CRUD by protoc-gen-gf
  • Copy the files to the package you want to place
  • Adjust the fields of Req and Res in the api
  • Adjust the fields of Input and Output in the model
  • Adjust the functions in the logic
  • Initialize your DB and NoSQL in the cmd
  • Initialize your logic in the cmd
  • Initialize your controller in the cmd
  • Run and Test

Environment

Download clis

Download protos

mkdir $GOPATH/src/google && cd $GOPATH/src/google
git clone --depth 1 https://github.com/googleapis/googleapis.git && mv googleapis/google/api $GOPATH/src/google && rm -rf googleapis
git clone --depth 1 https://github.com/protocolbuffers/protobuf.git protobuf1 && mv protobuf1/src/google/protobuf $GOPATH/src/google && rm -rf protobuf1
find $GOPATH/src/google -type f ! -name "*.proto" -delete && find $GOPATH/src/google -type d -empty -delete

Install

macOS & Linux

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
go install github.com/zcyc/protoc-gen-gf/protoc-gen-gf-api@main \
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-controller@main \
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-logic@main \
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-model@main \
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-client@main

Windows

PowerShell

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && `
go install github.com/zcyc/protoc-gen-gf/protoc-gen-gf-api@main `
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-controller@main `
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-logic@main `
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-model@main `
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-client@main

CMD

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && ^
go install github.com/zcyc/protoc-gen-gf/protoc-gen-gf-api@main ^
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-controller@main ^
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-logic@main ^
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-model@main ^
           github.com/zcyc/protoc-gen-gf/protoc-gen-gf-client@main

Usage

macOS & Linux

protoc -I ./api -I $GOPATH/src \
       --go_out ./api --go_opt=paths=source_relative \
       --gf-api_out ./api --gf-api_opt=paths=source_relative \
       --gf-controller_out ./api --gf-controller_opt=paths=source_relative \
       --gf-logic_out ./api --gf-logic_opt=paths=source_relative \
       --gf-model_out ./api --gf-model_opt=paths=source_relative \
       --gf-client_out ./api --gf-client_opt=paths=source_relative \
       ./api/v1/article.proto

Windows

PowerShell

protoc -I ./api -I $env:GOPATH/src `
       --go_out ./api --go_opt=paths=source_relative `
       --gf-api_out ./api --gf-api_opt=paths=source_relative `
       --gf-controller_out ./api --gf-controller_opt=paths=source_relative `
       --gf-logic_out ./api --gf-logic_opt=paths=source_relative `
       --gf-model_out ./api --gf-model_opt=paths=source_relative `
       --gf-client_out ./api --gf-client_opt=paths=source_relative `
       ./api/v1/article.proto

CMD

protoc -I ./api -I %GOPATH%/src ^
       --go_out ./api --go_opt=paths=source_relative ^
       --gf-api_out ./api --gf-api_opt=paths=source_relative ^
       --gf-controller_out ./api --gf-controller_opt=paths=source_relative ^
       --gf-logic_out ./api --gf-logic_opt=paths=source_relative ^
       --gf-model_out ./api --gf-model_opt=paths=source_relative ^
       --gf-client_out ./api --gf-client_opt=paths=source_relative ^
       ./api/v1/article.proto

Demo

artcle

Thanks