• Stars
    star
    424
  • Rank 101,660 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

😮 A surprisingly easy API server and generator in gRPC and Go

grapi

CI GoDoc Go Report Card GitHub release (latest SemVer) license

😮 A surprisingly easy API server and generator in gRPC and Go

Features

  • You can develop and deploy API servers blazingly fast
  • Easy code generator
    • application (inspired by rails new and create-react-app)
    • gRPC services and their implementations (inspired by rails g (scaffold_)controller)
  • User-friendly protoc wrapper (inspired by protoeasy)
  • Provides gRPC and HTTP JSON API with single implementation by using grpc-gateway
  • Generates codes based on google's API design guideline

asciicast

⚠️ Migrate 0.4.x -> 0.5.x ⚠️

grapiserver will not handle os signals from v0.5.x. We recommend to use appctx.Global() if you want to handle them.

📝 How to migrate
  1. Bump grapi version
  2. Update cmd/server/run.go
    •  	// Application context
      -	ctx := context.Background()
      +	ctx := appctx.Global()
    • -	return s.ServeContext(ctx)
      +	return s.Serve(ctx)

⚠️ Migrate 0.3.x -> 0.4.x ⚠️

Some tools that are depended by grapi are updated. If you have a grapi project <=v0.3.x, you should migrate it.

📝 How to migrate
  1. Bump grapi version
    • If you use dep, update Gopkg.toml
       [[constraint]]
         name = "github.com/izumin5210/grapi"
      -  version = "0.3.0"
      +  version = "0.4.0"
    • and run dep ensure
  2. Update gex and tools.go
    • go get -u github.com/izumin5210/gex/cmd/gex
      gex --regen
      
  3. Initialize Go Modules
    • go mod init
      go mod tidy
      
  4. Update grapi.toml
    • package = "yourcompany.yourappname"
      
      [grapi]
      server_dir = "./app/server"
      
      [protoc]
      protos_dir = "./api/protos"
      out_dir = "./api"
      import_dirs = [
        "./api/protos",
      -  "./vendor/github.com/grpc-ecosystem/grpc-gateway",
      -  "./vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis",
      +  '{{ module "github.com/grpc-ecosystem/grpc-gateway" }}',
      +  '{{ module "github.com/grpc-ecosystem/grpc-gateway" }}/third_party/googleapis',
      ]
      
        [[protoc.plugins]]
        name = "go"
        args = { plugins = "grpc", paths = "source_relative" }
      
        [[protoc.plugins]]
        name = "grpc-gateway"
        args = { logtostderr = true, paths = "source_relative" }
      
        [[protoc.plugins]]
        name = "swagger"
        args = { logtostderr = true }
  5. Drop dep
    • rm Gopkg.*
      

⚠️ Migrate 0.2.x -> 0.3.x ⚠️

grapi v0.3.0 has some breaking changes. If you have a grapi project <=v0.2.x, you should migrate it.

📝 How to migrate
  1. Bump grapi version
    • If you use dep, update Gopkg.toml
       [[constraint]]
         name = "github.com/izumin5210/grapi"
      -  version = "0.2.2"
      +  version = "0.3.0"
    • and run dep ensure
  2. Introduce gex
    • go get github.com/izumin5210/gex/cmd/gex
      
  3. Add defualt generator plugins:
    • gex \
        --add github.com/izumin5210/grapi/cmd/grapi \
        --add github.com/izumin5210/grapi/cmd/grapi-gen-command \
        --add github.com/izumin5210/grapi/cmd/grapi-gen-service \
        --add github.com/izumin5210/grapi/cmd/grapi-gen-scaffold-service \
        --add github.com/izumin5210/grapi/cmd/grapi-gen-type
      
  4. Add protoc plugins via gex
    • gex \
        --add github.com/golang/protobuf/protoc-gen-go \
        --add github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
        --add github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
      
    • Remove protoc plugins from Gopkg.toml
      -required = [
      -  "github.com/golang/protobuf/protoc-gen-go",
      -  "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway",
      -  "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger",
      -]
  5. Update grapi.toml
    • +package = "yourcompany.yourappname"
      +
       [grapi]
       server_dir = "./app/server"
      
       [protoc]
       protos_dir = "./api/protos"
       out_dir = "./api"
       import_dirs = [
      +  "./api/protos",
         "./vendor/github.com/grpc-ecosystem/grpc-gateway",
         "./vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis",
       ]
      
         [[protoc.plugins]]
      -  path = "./vendor/github.com/golang/protobuf/protoc-gen-go"
         name = "go"
         args = { plugins = "grpc", paths = "source_relative" }
      
         [[protoc.plugins]]
      -  path = "./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway"
         name = "grpc-gateway"
      -  args = { logtostderr = true }
      +  args = { logtostderr = true, paths = "source_relative" }
      
         [[protoc.plugins]]
      -  path = "./vendor/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger"
         name = "swagger"
         args = { logtostderr = true }

Getting Started

Create a new application

$ grapi init awesome-app

Create a new service

$ grapi g service books

Or, if you need full standard methods, you can get them with following command:

$ grapi g scaffold-service books

And you should register generated services to the grapiserver.Engine instance:

 // app/run.go
 
 // Run starts the grapiserver.
 func Run() error {
 	s := grapiserver.New(
 		grapiserver.WithDefaultLogger(),
 		grapiserver.WithServers(
+			server.NewBookServiceServer(),
-		// TODO
 		),
 	)
 	return s.Serve()
 }

If you updated service definition, you can re-generate .pb.go and .pb.gw.go with following command:

$ grapi protoc

Start server

$ grapi server

User-defined commands

$ grapi g command import-books
$ vim cmd/import-books/run.go  # implements the command
$ grapi import-books  # run the command

Build commands (including server)

$ grapi build

Installation

  1. grapi
    • Linux
      • curl -Lo grapi https://github.com/izumin5210/grapi/releases/download/v0.2.2/grapi_linux_amd64 && chmod +x grapi && sudo mv grapi /usr/local/bin
    • macOS
      • brew install izumin5210/tools/grapi
    • others
      • go get github.com/izumin5210/grapi/cmd/grapi
  2. dep or Modules
    • dep
      • macOS
        • brew install dep
      • others
        • See Installation · dep
        • curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
    • Modules (experimental)
      • Use Go 1.11 and set GO111MODULE=on your env vars
  3. protoc
    • macOS
      • brew install protobuf
    • others

More Repositories

1

Droidux

"Predictable state container" implementation, inspired by Redux.
Java
160
star
2

gex

The implementation of "clarify best practice for tool dependencies".
Go
50
star
3

Bletia

Promisified BLE library for Android.
Java
30
star
4

CiPointCloudViewer

Capturing and visualizing point clouds retrieved from multiple RGB-D cameras
C++
28
star
5

rspec-validator_spec_helper

Provide dummy class for validator spec
Ruby
20
star
6

cgt

🎨 Painting go test outputs
Go
15
star
7

hx

🌏 Developer-friendly, Real-World-ready and extensible HTTP client for Go
Go
12
star
8

action-homebrew-tap

JavaScript
11
star
9

dotfiles

My kitchen environment for cooking awesome products🍣🍣
Lua
10
star
10

clig

boilerplate generator and utilities for CLI tools in Go
Go
10
star
11

json-schema-parser

Parse JSON Schema and resolve `$ref` fields.
TypeScript
10
star
12

json-schema-mockifier

Generate mock object from JSON Schema (HyperSchema v4).
JavaScript
10
star
13

protogql

Build GraphQL schema and server from Protobuf
Go
9
star
14

nrgrpc

📈 gRPC `stats.Handler` implementation to measure and send performances metrics to New Relic
Go
9
star
15

rspec-cheki

Support snapshot testing, inspired Jest.
Ruby
8
star
16

tomatone

Simple pomodoro timer in your menubar
JavaScript
6
star
17

action-go-crossbuild

Build Go applications for multiplatform on GitHub Actions
JavaScript
6
star
18

scaffold

Customizable templates generator, inspired by Rails
Go
6
star
19

Sunazuri

esa.io client application for Android (unofficial)
Java
6
star
20

emojipack-for-devicon

Shell
6
star
21

pubee

Pluggable Pub/Sub Publisher
Go
5
star
22

ro

Redis Objects to Go
Go
5
star
23

redisync

Synchronization primitives with Redis
Go
4
star
24

jsonschema-study

Ruby
4
star
25

notebook-dockerfiles

Shell
4
star
26

actions-reviewdog

Dockerfile
4
star
27

actopus

Ruby
4
star
28

RxBleScanner

Java
4
star
29

homebrew-tools

Ruby
4
star
30

OHP

OHP is Hacker's Presentation writer with Markdown and CSS
JavaScript
3
star
31

gentleman-logger

Simplest logging plugin for gentleman HTTP client
Go
3
star
32

android-dockerfile

Ruby
3
star
33

orbs-for-tools

♻️ CircleCI Orbs for Continous-Delivery for Tools
Makefile
2
star
34

ridgepole-docker

Run ridgepole in docker
Dockerfile
2
star
35

hitorigoto_reporter

Post daily reports of slack channel to esa.io
Ruby
2
star
36

DialogFragmentBuilder_old

it makes you can use DialogFragment easily.
Java
2
star
37

ghsync

Go
2
star
38

nrredigo

Redigo connection wrapper with New Relic instrumentation for Go.
Go
2
star
39

go-dagger

Go
2
star
40

actions-github-release

Shell
1
star
41

televideo

Proxy server to record HTTP request/response with VCR
Ruby
1
star
42

action-setup-protobuf

JavaScript
1
star
43

font-awesome-helper

Useful helper for Font Awesome
Ruby
1
star
44

apidocgen

Dockerfile
1
star
45

dform

CLI to manage Dgraph schema
Go
1
star
46

ViewBorderHelper

Provides CSS-like border style to your custom views.
Java
1
star
47

nrgorm

Go
1
star
48

wannabe

Make everything be boolean (inspired by wannabe_bool)
Go
1
star
49

gin-zap

Go
1
star
50

httplogger

Go
1
star
51

go-cliapp-template

Template of a basic cli application with Golang
Go
1
star
52

SakeRadar

Java
1
star
53

actions-go-crossbuild-with-container

Dockerfile
1
star
54

graphql-fragment-mask

Mask GraphQL query result with Fragment
TypeScript
1
star
55

obsidian-iceberg

CSS
1
star
56

nrsql

SQL database driver wrapper with New Relic instrumentation for Go.
Go
1
star
57

DaggerHelpers

Java
1
star
58

scopedog

Democratize ActiveRecord's scopes
Ruby
1
star
59

asset_paths_from_manifest

Provides view helpers to compute full paths for assets from manifest json file
Ruby
1
star