Skip to content

Commit

Permalink
Merge pull request #24 from bootun/master
Browse files Browse the repository at this point in the history
migration CI
  • Loading branch information
GrantZheng authored Jan 16, 2022
2 parents ce87867 + 329cc83 commit 4a08cdf
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 46 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/commit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17

- name: Build
run: go build -v ./...

- name: Test
run: |
go test -race -v ./...
- name: Install
run: go install .

- name: Generate Code
run: |
chmod +x ./script/gen_test.sh
./script/gen_test.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ vendor/
.idea
*.iml
.vscode/
temp/
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# GoKit CLI [![Build Status](https://travis-ci.org/kujtimiihoxha/kit.svg?branch=master)](https://travis-ci.org/kujtimiihoxha/kit)[![Go Report Card](https://goreportcard.com/badge/github.com/kujtimiihoxha/kit)](https://goreportcard.com/report/github.com/kujtimiihoxha/kit)[![Coverage Status](https://coveralls.io/repos/github/kujtimiihoxha/kit/badge.svg?branch=master)](https://coveralls.io/github/kujtimiihoxha/kit?branch=master)
I fork the project from [kit](https://github.com/kujtimiihoxha/kit) and plan to maintain it in the future. The kit tool is a great job, and deeply used in our team. Some features and bugs have been done and fixed, such as supporting go module,replacing some old dependencies and so on. I am very glad to receive recommend about it.
# GoKit CLI [![Build Status](https://github.com/GrantZheng/kit/workflows/Go/badge.svg)](https://github.com/GrantZheng/kit/actions)[![Go Report Card](https://goreportcard.com/badge/github.com/GrantZheng/kit)](https://goreportcard.com/report/github.com/GrantZheng/kit)[![Coverage Status](https://coveralls.io/repos/github/GrantZheng/kit/badge.svg?branch=master)](https://coveralls.io/github/GrantZheng/kit?branch=master)
I fork the project from [kit](https://github.com/kujtimiihoxha/kit) and plan to maintain it in the future. The kit tool is a great job, and deeply used in our team. Some features and bugs have been done and fixed, such as supporting go module,replacing some old dependencies and so on. I am very glad to receive recommend about it.

This project is a more advanced version of [gk](https://github.com/kujtimiihoxha/gk).
The goal of the gokit cli is to be a tool that you can use while you develop your microservices with `gokit`.
Expand All @@ -8,22 +8,22 @@ While `gk` did help you create your basic folder structure it was not really abl
This is what `GoKit Cli` is aiming to change.


# Prerequisites
# Prerequisites
`Go` is a requirement to be able to test your services.[gokit](https://github.com/go-kit/kit) is needed.To utilise generation of gRPC service code through kit generate service <SERVICE_NAME> -t grpc you will need to install the [grpc prequisites](https://grpc.io/docs/languages/go/quickstart/).
```
go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/protoc-gen-go
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
```

# Table of Content
- [Installation](#installation)
- [Usage](#usage)
- [Create a new service](#create-a-new-service)
- [Generate the service](#generate-the-service)
- [Generate the client library](#generate-the-client-library)
- [Generate new middlewares](#generate-new-middleware)
- [Enable docker integration](#enable-docker-integration)
- [Installation](#installation)
- [Usage](#usage)
- [Create a new service](#create-a-new-service)
- [Generate the service](#generate-the-service)
- [Generate the client library](#generate-the-client-library)
- [Generate new middlewares](#generate-new-middleware)
- [Enable docker integration](#enable-docker-integration)

# Installation
Before you install please read [prerequisites](#prerequisites)
```bash
Expand Down Expand Up @@ -80,12 +80,12 @@ This command will do these things:
- If using` --dmw` create the endpoint middleware: `hello/pkg/endpoint/middleware.go`
- Create the transport files e.x `http`: `service-name/pkg/http/handler.go`
- Create the service main file :boom:
`hello/cmd/service/service.go`
`hello/cmd/service/service_gen.go`
`hello/cmd/main.go`
`hello/cmd/service/service.go`
`hello/cmd/service/service_gen.go`
`hello/cmd/main.go`

:warning: **Notice** all the files that end with `_gen` will be regenerated when you add endpoints to your service and
you rerun `kit g s hello` :warning:
:warning: **Notice** all the files that end with `_gen` will be regenerated when you add endpoints to your service and
you rerun `kit g s hello` :warning:

You can run the service by running:
```bash
Expand Down Expand Up @@ -133,12 +133,12 @@ The only thing left to do is add your middleware logic and wire the middleware w
```bash
kit g d
```
This will add the individual service docker files and one `docker-compose.yml` file that will allow you to start
This will add the individual service docker files and one `docker-compose.yml` file that will allow you to start
your services.
To start your services just run
To start your services just run
```bash
docker-compose up
```

After you run `docker-compose up` your services will start up and any change you make to your code will automatically
rebuild and restart your service (only the service that is changed)
rebuild and restart your service (only the service that is changed)
38 changes: 27 additions & 11 deletions generator/add_transport.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package generator

import (
"bytes"
"fmt"
"path"
"strings"

"bytes"

"os/exec"

"os"
Expand Down Expand Up @@ -707,8 +706,14 @@ func (g *generateGRPCTransportProto) Generate() (err error) {
&proto.Package{
Name: "pb",
},
&proto.Option{
Comment: nil,
Name: "go_package",
Constant: proto.Literal{Source: fmt.Sprintf(`"%s"`, g.destPath)},
},
svc,
)

} else {
s := g.getService()
if s == nil {
Expand All @@ -729,8 +734,14 @@ func (g *generateGRPCTransportProto) Generate() (err error) {
g.pbFilePath = path.Join(viper.GetString("gk_folder"), g.pbFilePath)
}
if !viper.GetBool("gk_testing") {
cmd := exec.Command("protoc", g.pbFilePath, "--go_out=plugins=grpc:.")
cmd := exec.Command("protoc",
"--go_out=.", "--go_opt=paths=source_relative",
"--go-grpc_out=.", "--go-grpc_opt=paths=source_relative",
g.pbFilePath)
cmd.Stdout = os.Stdout
// In case there is an error in protoc, user can receive error, otherwise,
// they can only receive "ERRO[0000] exit status 1". see issue #18
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
return err
Expand All @@ -748,13 +759,14 @@ func (g *generateGRPCTransportProto) Generate() (err error) {
fmt.Sprintf(`:: Install proto3.
:: https://github.com/google/protobuf/releases
:: Update protoc Go bindings via
:: go get -u github.com/golang/protobuf/proto
:: go get -u github.com/golang/protobuf/protoc-gen-go
:: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
:: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
::
:: See also
:: https://github.com/grpc/grpc-go/tree/master/examples
protoc %s.proto --go_out=plugins=grpc:.`, g.name),
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative %s`, g.name),
false,
)
}
Expand All @@ -769,12 +781,13 @@ protoc %s.proto --go_out=plugins=grpc:.`, g.name),
# ./autogen.sh ; ./configure ; make ; make install
#
# Update protoc Go bindings via
# go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
#
# go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
# go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# See also
# https://github.com/grpc/grpc-go/tree/master/examples
protoc %s.proto --go_out=plugins=grpc:.`, g.name),
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative %s`, g.name),
false,
)
}
Expand All @@ -794,12 +807,14 @@ protoc %s.proto --go_out=plugins=grpc:.`, g.name),
# sudo ldconfig # refresh shared library cache.
#
# Update protoc Go bindings via
# go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
# go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
# go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
#
# See also
# https://github.com/grpc/grpc-go/tree/master/examples
protoc %s.proto --go_out=plugins=grpc:.`, g.name),
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative %s`, g.name),
false,
)
}
Expand Down Expand Up @@ -940,6 +955,7 @@ func (g *generateGRPCTransportBase) Generate() (err error) {
}
fields = append(fields, jen.Id(n).Qual("github.com/go-kit/kit/transport/grpc", "Handler"))
}
fields = append(fields, jen.Id("").Qual(pbImport, "Unimplemented"+utils.ToCamelCase(g.name)+"Server"))
} else {
for _, m := range g.serviceInterface.Methods {
n := utils.ToLowerFirstCamelCase(m.Name)
Expand Down
24 changes: 24 additions & 0 deletions script/gen_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
serviceCode='package service
import "context"
type HelloService interface {
Foo(ctx context.Context,s string)(rs string, err error)
Bar(ctx context.Context,i int)(rs int, err error)
}'


if [ -d temp ]; then
cd temp || exit
else
mkdir temp && cd temp || exit
fi
# generate project
kit n s hello
echo "$serviceCode" > ./hello/pkg/service/service.go
kit g s hello
kit g s hello -t grpc
cd ./hello || exit
go mod tidy -compat=1.17
go build -v ./...

0 comments on commit 4a08cdf

Please sign in to comment.