All Projects → pacedotdev → Oto

pacedotdev / Oto

Licence: mit
Go driven rpc code generation tool for right now.

Programming Languages

javascript
184084 projects - #8 most used programming language
go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Oto

Thriftpy2
Pure python approach of Apache Thrift.
Stars: ✭ 402 (-15.9%)
Mutual labels:  rpc
Happypandax
A cross-platform server and client application for managing and reading manga and doujinshi
Stars: ✭ 432 (-9.62%)
Mutual labels:  rpc
Rpc Benchmark
java rpc benchmark, 灵感源自 https://www.techempower.com/benchmarks/
Stars: ✭ 463 (-3.14%)
Mutual labels:  rpc
Go Dexec
It's like Go os/exec package but for Docker. What if you could exec programs remotely with the same interface as os/exec?
Stars: ✭ 407 (-14.85%)
Mutual labels:  rpc
Vs Streamjsonrpc
The StreamJsonRpc library offers JSON-RPC 2.0 over any .NET Stream, WebSocket, or Pipe. With bonus support for request cancellation, client proxy generation, and more.
Stars: ✭ 421 (-11.92%)
Mutual labels:  rpc
Airframe
Essential Building Blocks for Scala
Stars: ✭ 442 (-7.53%)
Mutual labels:  rpc
Redeo
High-performance framework for building redis-protocol compatible TCP servers/services
Stars: ✭ 392 (-17.99%)
Mutual labels:  rpc
Dora Rpc
DoraRPC is an RPC For the PHP MicroService by The Swoole
Stars: ✭ 475 (-0.63%)
Mutual labels:  rpc
Izumi
Productivity-oriented collection of lightweight fancy stuff for Scala toolchain
Stars: ✭ 423 (-11.51%)
Mutual labels:  rpc
Elle
The Elle coroutine-based asynchronous C++ development framework.
Stars: ✭ 459 (-3.97%)
Mutual labels:  rpc
Hydra
后端一站式微服务框架,提供API、web、websocket,RPC、任务调度、消息消费服务器
Stars: ✭ 407 (-14.85%)
Mutual labels:  rpc
Torat
ToRat is a Remote Administation tool written in Go using Tor as a transport mechanism and RPC for communication
Stars: ✭ 415 (-13.18%)
Mutual labels:  rpc
Nswag
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
Stars: ✭ 4,825 (+909.41%)
Mutual labels:  codegen
Udash Core
Scala framework for building beautiful and maintainable web applications.
Stars: ✭ 405 (-15.27%)
Mutual labels:  rpc
Poc
Proofs-of-concept
Stars: ✭ 467 (-2.3%)
Mutual labels:  rpc
Guardrail
Principled code generation from OpenAPI specifications
Stars: ✭ 396 (-17.15%)
Mutual labels:  codegen
Pyrlang
Erlang node implemented in Python 3.5+ (Asyncio-based)
Stars: ✭ 436 (-8.79%)
Mutual labels:  rpc
Rpc
A golang foundation for RPC over HTTP services.
Stars: ✭ 474 (-0.84%)
Mutual labels:  rpc
Flapigen Rs
Tool for connecting programs or libraries written in Rust with other languages
Stars: ✭ 473 (-1.05%)
Mutual labels:  codegen
Apps
Basic Polkadot/Substrate UI for interacting with a node. This is the main user-facing application, allowing access to all features available on Substrate chains.
Stars: ✭ 451 (-5.65%)
Mutual labels:  rpc

Welcome to oto project

Go driven rpc code generation tool for right now.

  • 100% Go
  • Describe services with Go interfaces (with structs, methods, comments, etc.)
  • Generate server and client code
  • Production ready templates (or copy and modify)

Who's using Oto?

  • Pace.dev - Oto came out of the Pace project
  • Firesearch.dev - Firesearch uses Oto to offer full-text services to the web, mobile, and the backend

Templates

These templates are already being used in production.

Learn

Tutorial

Install the project:

go install github.com/pacedotdev/oto

Create a project folder, and write your service definition as a Go interface:

// definitions/definitons.go
package definitions

// GreeterService makes nice greetings.
type GreeterService interface {
    // Greet makes a greeting.
    Greet(GreetRequest) GreetResponse
}

// GreetRequest is the request object for GreeterService.Greet.
type GreetRequest struct {
    // Name is the person to greet.
    // example: "Mat Ryer"
    Name string
}

// GreetResponse is the response object containing a
// person's greeting.
type GreetResponse struct {
    // Greeting is the greeting that was generated.
    // example: "Hello Mat Ryer"
    Greeting string
}

Download templates from otohttp

mkdir templates \
    && wget https://raw.githubusercontent.com/pacedotdev/oto/master/otohttp/templates/server.go.plush -q -O ./templates/server.go.plush \
    && wget https://raw.githubusercontent.com/pacedotdev/oto/master/otohttp/templates/client.js.plush -q -O ./templates/client.js.plush

Use the oto tool to generate a client and server:

mkdir generated
oto -template ./templates/server.go.plush \
    -out ./generated/oto.gen.go \
    -ignore Ignorer \
    -pkg generated \
    ./definitions
gofmt -w ./generated/oto.gen.go ./generated/oto.gen.go
oto -template ./templates/client.js.plush \
    -out ./generated/oto.gen.js \
    -ignore Ignorer \
    ./definitions
  • Run oto -help for more information about these flags

Implement the service in Go:

// greeter_service.go
package main

// GreeterService makes nice greetings.
type GreeterService struct{}

// Greet makes a greeting.
func (GreeterService) Greet(ctx context.Context, r GreetRequest) (*GreetResponse, error) {
    resp := &GreetResponse{
        Greeting: "Hello " + r.Name,
    }
    return resp, nil
}

Use the generated Go code to write a main.go that exposes the server:

// main.go
package main

func main() {
    g := GreeterService{}
    server := otohttp.NewServer()
    generated.RegisterGreeterService(server, g)
    http.Handle("/oto/", server)
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Use the generated client to access the service in JavaScript:

import { GreeterService } from "oto.gen.js";

const greeterService = new GreeterService();

greeterService
    .greet({
        name: "Mat"
    })
    .then(response => alert(response.greeting))
    .catch(e => alert(e));

Specifying additional template data

You can provide strings to your templates via the -params flag:

oto \
    -template ./templates/server.go.plush \
    -out ./oto.gen.go \
    -params "key1:value1,key2:value2" \
    ./path/to/definition

Within your templates, you may access these strings with <%= params["key1"] %>.

Comment metadata

It's possible to include additional metadata for services, methods, objects, and fields in the comments.

// Thing does something.
// field: "value"
type Thing struct {
    //...
}

The Metadata["field"] value will be the string value.

  • The value must be valid JSON (for strings, use quotes)

Examples are officially supported, but all data is available via the Metadata map fields.

Examples

To provide an example value for a field, you may use the example: prefix line in a comment.

// GreetRequest is the request object for GreeterService.Greet.
type GreetRequest struct {
    // Name is the person to greet.
    // example: "Mat Ryer"
    Name string
}
  • The example must be valid JSON

The example is extracted and made available via the Field.Example field.

Contributions

Special thank you to:

A PACE. project

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].