GoKit CLI

GoKit CLI Build StatusGo Report CardCoverage Status

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

GoKit Cli needs to be installed using go get and go install so Go is a requirement to be able to test your services gokit 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.

go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/protoc-gen-go

Table of Content

Installation

Before you install please read prerequisites

go get github.com/kujtimiihoxha/kit

Usage

kit help

Also read this medium story

Create a new service

kit new service hello
kit n s hello # using aliases

This will generate the initial folder structure 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)
}

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 💥
    hello/cmd/service/service.go
    hello/cmd/service/service_gen.go
    hello/cmd/main.go

⚠️ 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 ⚠️

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

Owner
Kujtim Hoxha
Electronics/Software Engineer, open-source enthusiast. Go,Python,Javascript...
Kujtim Hoxha
Comments
  • Make easy update : Separate gen file et hand written file

    Make easy update : Separate gen file et hand written file

    The need to modify generated .go file, looks like the need to modify the .asm file generated by a c compiler.

    It's complex to update the generated part, when the generator need to be re-run and the file are modified by hand.

    It will be great if kit could be used with "go generate", and if there inputs are considered as source code.

  • kit cmd error

    kit cmd error

    I install the kit follow the doc, but when I try "kit help", the error happen. ERRO[0000] The project must be in the $GOPATH/src folder for the generator to work.

  • thrift.TClient undefined

    thrift.TClient undefined

    I'm trying out this CLI tool as it looks the most capable from what I see so far but i have this issue with thrift.TClient

    # user/vendor/github.com/openzipkin/zipkin-go-opentracing/thrift/gen-go/scribe
    vendor/github.com/openzipkin/zipkin-go-opentracing/thrift/gen-go/scribe/scribe.go:210:5: undefined: thrift.TClient
    

    It this point the only thing i did is to follow your tutorial. Can you please help me with this? Thanks you.

  • "kit g s" cannot generate function with optional parameter defined.

    When using "kit g s servicename", if a function is defined with optional parameter, seems kit not recognize "..." my interface defined as below:

    package service
    
    import (
            "context"
            "github.com/burxtx/fault/fault/pkg/model"
    )
    
    // FaultService describes the service.
    type FaultService interface {
            // Add your methods here
            Find(ctx context.Context, condiBeans...interface{}) (m []model.Fault, error error)
            Get(ctx context.Context, id string) (m model.Fault, error error)
            Add(ctx context.Context, fault model.Fault) (i int64, error error)
    }
    

    then type "kit g s fault -w --gorilla"

    INFO[0000] Type Expresion not supported                 
    panic: Error 1:76: expected type, found ')' while formatting source:
    func (b *basicFaultService) Find (ctx context.Context,condiBeans ) (m0 []model.Fault,e1 error) {
    // TODO implement the business logic of Find
    return m0,e1
    } 
    
    goroutine 1 [running]:
    github.com/dave/jennifer/jen.(*Statement).GoString(0xc4200cfbc0, 0x1, 0x1)
    	/root/go/src/github.com/dave/jennifer/jen/statement.go:93 +0x102
    github.com/kujtimiihoxha/kit/generator.(*PartialGenerator).String(0xc42000e1f0, 0xc420018c01, 0x5ea)
    	/root/go/src/github.com/kujtimiihoxha/kit/generator/generator.go:213 +0x2e
    github.com/kujtimiihoxha/kit/generator.(*GenerateService).Generate(0xc420290000, 0x5, 0xa5b916)
    	/root/go/src/github.com/kujtimiihoxha/kit/generator/generate_service.go:91 +0x356
    github.com/kujtimiihoxha/kit/cmd.glob..func3(0xe75880, 0xc42014ecc0, 0x1, 0x3)
    	/root/go/src/github.com/kujtimiihoxha/kit/cmd/g_service.go:41 +0x175
    github.com/spf13/cobra.(*Command).execute(0xe75880, 0xc42014ec30, 0x3, 0x3, 0xe75880, 0xc42014ec30)
    	/root/go/src/github.com/spf13/cobra/command.go:750 +0x2c1
    github.com/spf13/cobra.(*Command).ExecuteC(0xe76180, 0x0, 0x0, 0xc420197ed8)
    	/root/go/src/github.com/spf13/cobra/command.go:831 +0x30e
    github.com/spf13/cobra.(*Command).Execute(0xe76180, 0x2, 0x2)
    	/root/go/src/github.com/spf13/cobra/command.go:784 +0x2b
    github.com/kujtimiihoxha/kit/cmd.Execute()
    	/root/go/src/github.com/kujtimiihoxha/kit/cmd/root.go:24 +0x31
    main.main()
    	/root/go/src/github.com/kujtimiihoxha/kit/main.go:29 +0x117```
  •  make endpoints name to const defines in endpoint_gen.go

    make endpoints name to const defines in endpoint_gen.go

    declare const for endpoint name. so you don't have to remenber the key string for endpoint when creating middleware the sample of endpoint_gen.go before

    for _, m := range mdw[“CheckOTP”] {
    	eps.CheckOTPEndpoint = m(eps.CheckOTPEndpoint)
    }
    

    after

    // Endpoints Name inside Service
    const (
    	EpCheckOTPName      = "CheckOTP"
    	EpCheckPasswordName = "CheckPassword"
    )
    
    for _, m := range mdw[EpCheckOTPName] {
    	eps.CheckOTPEndpoint = m(eps.CheckOTPEndpoint)
    }
    
  • How to add self-created middleware to the addDefaultEndpointMiddleware automaticly

    How to add self-created middleware to the addDefaultEndpointMiddleware automaticly

    Hi, like the title, how to add self-created middleware to the addDefaultEndpointMiddleware function automaticly,l like the InstrumentingMiddleware and the LoggingMiddleware? thanks

  • Don't exit if $GOPATH/src is a symlink

    Don't exit if $GOPATH/src is a symlink

    EvalSymlinks() before comparing the pwd with $GOPATH/src so that in the case where $GOPATH/src is a symbolic link (to a case sensitive filesystem on a mac for instance) the kit command will still execute successfully.

    I'm not sure if this is too much of an edge case to handle in the code or not, but on my particular setup $GOPATH/src is a symlink to Volumes/src, which is a case-sensitive volume on my mac. The reason for this is so that I don't have to worry about issues related to case insensitivity on the standard HFS+ volume.

    In theory, I could mitigate this issue by moving all of $GOPATH to /Volumes/src w/out having to change the code.

    Let me know what you think, and if this change is appropriate or not.

  • how to set GET,POST and so on to a handle

    how to set GET,POST and so on to a handle

    just like title,how to...

    func makeCreateHandler(m *http.ServeMux, endpoints endpoint.Endpoints, options []http1.ServerOption) { m.Handle("/create", http1.NewServer(endpoints.CreateEndpoint, decodeCreateRequest, encodeCreateResponse, options...)) }

  • install error

    install error

    → go get github.com/kujtimiihoxha/kit

    github.com/spf13/cobra

    ../gopath/src/github.com/spf13/cobra/command.go:31:25: undefined: pflag.ParseErrorsWhitelist

  • Panics when create new service: panic: Error 5:7: illegal floating-point exponent while formatting source

    Panics when create new service: panic: Error 5:7: illegal floating-point exponent while formatting source

    Code is simple with platform win10 x64:

    kit n s 360.exapi.wy
    

    and it panics:

    panic: Error 5:7: illegal floating-point exponent while formatting source:
    package service
    
    
     // 360ExapiWyService describes the service.
     type 360ExapiWyService interface{
    // Add your methods here
     // e.x: Foo(ctx context.Context,s string)(rs string, err error)
    }
    
    
    goroutine 1 [running]:
    github.com/dave/jennifer/jen.(*File).GoString(0xc000207c20, 0xc0000755c0, 0x11)
            E:/GoProjects/src/github.com/dave/jennifer/jen/file.go:235 +0x10a
    github.com/kujtimiihoxha/kit/generator.(*NewService).Generate(0xc0000cf320, 0xc, 0xce1340)
            E:/GoProjects/src/github.com/kujtimiihoxha/kit/generator/new_service.go:54 +0x33f
    github.com/kujtimiihoxha/kit/cmd.glob..func8(0x11864e0, 0xc000168d00, 0x1, 0x1)
            E:/GoProjects/src/github.com/kujtimiihoxha/kit/cmd/service.go:19 +0x64
    github.com/spf13/cobra.(*Command).execute(0x11864e0, 0xc000168cb0, 0x1, 0x1, 0x11864e0, 0xc000168cb0)
            E:/GoProjects/src/github.com/spf13/cobra/command.go:766 +0x2b5
    github.com/spf13/cobra.(*Command).ExecuteC(0x1186280, 0x0, 0x22, 0xc0000753c0)
            E:/GoProjects/src/github.com/spf13/cobra/command.go:850 +0x303
    github.com/spf13/cobra.(*Command).Execute(...)
            E:/GoProjects/src/github.com/spf13/cobra/command.go:800
    github.com/kujtimiihoxha/kit/cmd.Execute()
            E:/GoProjects/src/github.com/kujtimiihoxha/kit/cmd/root.go:24 +0x39
    main.main()
            E:/GoProjects/src/github.com/kujtimiihoxha/kit/main.go:40 +0x306
    
  • Typo

    Typo

    https://github.com/kujtimiihoxha/kit/blob/b012bbc7eb2535211e4b814969f01d030c835895/generator/generate_client.go#L462

    "impelemented" -> "implemented"

    Also

    https://github.com/kujtimiihoxha/kit/blob/b012bbc7eb2535211e4b814969f01d030c835895/generator/generate_client.go#L486

  • go-kit generate service error

    go-kit generate service error

    This error occurs while executing the following command : kit generate service -t grpc --dmw

    The /grpc/pb folder only contains the .proto file. The compile.sh and .pb.go files seem to be missing.

    I installed the protoc compiler and protocol compiler plugins for Go. But still got that "ERRO[0000] exit status 1 error"

  • Cannot install On MacOS with go 1.18.2 release

    Cannot install On MacOS with go 1.18.2 release

    #go version
    go version go1.18.2 darwin/arm64
    
    #go install github.com/kujtimiihoxha/kit@latest
    # golang.org/x/sys/unix
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:28:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:43:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:59:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:75:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:90:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:105:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:121:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:136:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:151:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:166:3: //go:linkname must refer to declared function or variable
    ../go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:166:3: too many errors
    
  • Bump gopkg.in/yaml.v2 from 2.2.2 to 2.2.8

    Bump gopkg.in/yaml.v2 from 2.2.2 to 2.2.8

    Bumps gopkg.in/yaml.v2 from 2.2.2 to 2.2.8.

    Commits
    • 53403b5 Optimize cases with long potential simple_keys (#555)
    • 1f64d61 Fix issue in simple_keys improvements (#548)
    • a95acef Update travis config to use latest go versions (#540)
    • 36babc3 Port stale simple_keys fix to v2 (#543)
    • 770b8da Fix Decorder doc typo (#494)
    • 1ed5951 Add Go 1.10-13 to travis setup.
    • f90ceb4 Fix check for non-map alias merging in v2 (#529)
    • 970885f Trivial style tuning on last change.
    • f221b84 Improve heuristics preventing CPU/memory abuse (#515)
    • bb4e33b Add logic to catch cases of alias abuse.
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

  • Installation Instructions are missing key context/steps to be successful in modern Go versions

    Installation Instructions are missing key context/steps to be successful in modern Go versions

    Hi,

    I'm admittedly brand new in go. I'm familiar with Go modules, and with none of the older outdated setup methods. I've installed Go 1.15 based on the most up to date install instructions (https://golang.org/doc/install - I am using a system-wide install in /usr/local/)

    I can't figure out if I am meant to be in a project or just anywhere when I run

    go get github.com/kujtimiihoxha/kit
    

    The command runs fine when I am in a project, but it installs it in the project (expected) and the next command go install kit fails as it is looking in /usr/local for the file:

    ❯ go install kit
    package kit is not in GOROOT (/usr/local/go/src/kit)
    

    Trying to run go get github.com/kujtimiihoxha/kit in any shell outside a project just fails silently.

    I imagine I could clone the whole repo into /usr/local/go/src/kit - but is that the proper method? Is that going to mess things up? I don't know - as no context is given in the instructions.

    Can you please update the directions to provide the missing context here? This application is aim at people new to Go-Kit, and presumably go, so as such I feel they are somewhat lacking.

  • Generate service error

    Generate service error

    version

    go version

    go version go1.14.8 darwin/amd64
    

    Error

    The build service must be in the gopath / SRC directory

    ERRO[0000] lstat /opt/gopath/src: no such file or directory
    
String Service. Microservice example using gokit library

Example of Microservices using go-kit Go kit is a collection of Go (golang) packages (libraries) that help you build robust, reliable, maintainable mi

Dec 6, 2021
Go micro frame cli tool

go-micro-frame cli tool install git clone [email protected]:jettjia/go-micro-frame-cli.git cd go-micro-frame-cli go build -ldflags "-w -s" -o go-micro-f

Sep 19, 2022
White Matrix Micro Service Generate CLI Tool

micro-service-gen-tool White Matrix Micro Service Generate CLI Tool usage templa

Jan 5, 2022
Código da palestra sobre Microsserviços usando Gokit

Código da palestra sobre Microsserviços usando Gokit

Dec 10, 2022
String Service. Microservice example using gokit library

Example of Microservices using go-kit Go kit is a collection of Go (golang) packages (libraries) that help you build robust, reliable, maintainable mi

Dec 6, 2021
Elegant CLI wrapper for kubeseal CLI

Overview This is a wrapper CLI ofkubeseal CLI, specifically the raw mode. If you just need to encrypt your secret on RAW mode, this CLI will be the ea

Jan 8, 2022
Network cli based on urfave/cli package

go_network_cli network cli based on urfave/cli package available on Working for ip, cname and mx. Use --hel

Nov 28, 2021
Traefik config validator: a CLI tool to (syntactically) validate your Traefik configuration filesTraefik config validator: a CLI tool to (syntactically) validate your Traefik configuration files
Traefik config validator: a CLI tool to (syntactically) validate your Traefik configuration filesTraefik config validator: a CLI tool to (syntactically) validate your Traefik configuration files

Traefik Config Validator Note This is currently pre-release software. traefik-config-validator is a CLI tool to (syntactically) validate your Traefik

Dec 16, 2021
CLI to run a docker image with R. CLI built using cobra library in go.
CLI  to run a docker image with R. CLI built using cobra library in go.

BlueBeak Installation Guide Task 1: Building the CLI The directory structure looks like Fastest process: 1)cd into bbtools 2)cd into bbtools/bin 3)I h

Dec 20, 2021
A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode.

aliyun-dns A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode. Installation Install aliyun-cli. Usage $ aliyun-dns -h A wra

Dec 21, 2021
Symfony-cli - The Symfony CLI tool For Golang

Symfony CLI Install To install Symfony CLI, please download the appropriate vers

Dec 28, 2022
Go-file-downloader-ftctl - A file downloader cli built using golang. Makes use of cobra for building the cli and go concurrent feature to download files.

ftctl This is a file downloader cli written in Golang which uses the concurrent feature of go to download files. The cli is built using cobra. How to

Jan 2, 2022
Cli-algorithm - A cli program with A&DS in go!

cli-algorithm Objectives The objective of this cli is to implement 4 basic algorithms to sort arrays been Merge Sort Insertion Sort Bubble Sort Quick

Jan 2, 2022
Nebulant-cli - Nebulant's CLI
Nebulant-cli - Nebulant's CLI

Nebulant CLI Website: https://nebulant.io Documentation: https://nebulant.io/docs.html The Nebulant CLI tool is a single binary that can be used as a

Jan 11, 2022
Cf-cli-find-app-plugin - CF CLI plugin to find applications containing a search string

Overview This cf cli plugin allows users to search for application names that co

Jan 3, 2022
Alertmanager-cli is a cli writtin in golang to silence alerts in AlertManager

Alertmanager-cli is a cli writtin in golang to silence alerts in AlertManager

Aug 27, 2022
News-parser-cli - Simple CLI which allows you to receive news depending on the parameters passed to it
News-parser-cli - Simple CLI which allows you to receive news depending on the parameters passed to it

news-parser-cli Simple CLI which allows you to receive news depending on the par

Jan 4, 2022
Go-api-cli - Small CLI to fetch data from an API sync and async

Async API Cli CLI to fetch data on "todos" from a given API in a number of ways.

Jan 13, 2022
Syno-cli - Synology unofficial API CLI and library

Synology CLI Unofficial wrapper over Synology API in Go. Focus on administrative

Jan 6, 2023