1 Star 0 Fork 0

高跃 / kit-cli

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

GoKit CLI Build StatusGo Report CardCoverage Status

I fork the project from 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. The goal of the gokit cli is to be a tool that you can use while you develop your microservices with gokit.

While gk did help you create your basic folder structure it was not really able to be used further on in your project. This is what GoKit Cli is aiming to change.

Prerequisites

Go is a requirement to be able to test your services gokit is needed.

Table of Content

Installation

Before you install please read prerequisites

git clone https://gitee.com/nmggy/kit-cli.git
cd kit
go install 

:warning: Notice: to install package, do not use go get github.com/GrantZheng/kit, which could generate kit binary refers to the original repo code. Some methods have been discussed here,but I haven't found a better way to solve this problem.

Usage

kit help

Also read this medium story

Create a new service

The kit tool use modules to manage dependencies by default, please make sure your go version >= 1.3, or GO111MODULE is set on. If you want to specify the module name, you should use the --module flag, otherwise, the module name in the go.mod file will be set as your project name.

kit new service --help
kit new service hello
kit n s hello # using aliases

or

kit new service hello --module github.com/{group name}/hello
kit n s hello -m github.com/{group name}/hello # using aliases

This will generate the initial folder structure, the go.mod file and the service interface

service-name/pkg/service/service.go

package service

// HelloService describes the service.
type HelloService interface {
	// Add your methods here
	// e.x: Foo(ctx context.Context,s string)(rs string, err error)
}

When you are generating the service and the client library, the module name in the go.mod file could be autodetected.

Generate the service

kit g s hello
kit g s hello --dmw # to create the default middleware
kit g s hello -t grpc # specify the transport (default is http)

This command will do these things:

  • Create the service boilerplate: hello/pkg/service/service.go
  • Create the service middleware: hello/pkg/service/middleware.go
  • Create the endpoint: hello/pkg/endpoint/endpoint.go and hello/pkg/endpoint/endpoint_gen.go
  • 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

: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:

go run hello/cmd/main.go

Generate the client library

kit g c hello

This will generate the client library :sparkles: http/client/http/http.go that you can than use to call the service methods, you can use it like this:

package main

import (
	"context"
	"fmt"

	client "hello/client/http"
	"github.com/go-kit/kit/transport/http"
)

func main() {
	svc, err := client.New("http://localhost:8081", map[string][]http.ClientOption{})
	if err != nil {
		panic(err)
	}

	r, err := svc.Foo(context.Background(), "hello")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	fmt.Println("Result:", r)
}

Generate new middleware

kit g m hi -s hello
kit g m hi -s hello -e # if you want to add endpoint middleware

The only thing left to do is add your middleware logic and wire the middleware with your service/endpoint.

Enable docker integration

kit g d

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

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)

The MIT License (MIT) Copyright (c) 2017 Kujtim Hoxha Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

kit-cli 展开 收起
Go 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/nmggy/kit-cli.git
git@gitee.com:nmggy/kit-cli.git
nmggy
kit-cli
kit-cli
master

搜索帮助