82

GitHub - izumin5210/grapi: ? A surprisingly easy API server and generator in gRP...

 6 years ago
source link: https://github.com/izumin5210/grapi
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

grapi

Build Status GoDoc Go Report Card Go project version license

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

Features

  • You can develop and deploy API servers blazing fastly ⚡️
  • Easily 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 followed google's API design guideline

asciicast

Getting Started

Installation

For Homebrew users

$ brew install protobuf
$ brew install izumin5210/tools/grapi

Downloads built binary

You should install protoc command from google/protobuf.

  • Linux:
    • curl -Lo grapi https://github.com/izumin5210/grapi/releases/download/v0.2.0/grapi_linux_amd64 && chmod +x grapi && sudo mv grapi /usr/local/bin
  • masOS:
    • curl -Lo grapi https://github.com/izumin5210/grapi/releases/download/v0.2.0/grapi_darwin_amd64 && chmod +x grapi && sudo mv grapi /usr/local/bin

Creates a new application

$ grapi init awesome-app

Creates 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 the following command:

$ grapi protoc

Starts 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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK