Code Monkey home page Code Monkey logo

begonia-rpc's Introduction

Begonia-RPC

A golang rpc framework for efficient and concise.

User Guide

Prerequisites

Golang Version >= 1.11.2

Installation

$ go get github.com/MashiroC/begonia-rpc

Example

service center

package main

import (
	"github.com/MashiroC/begonia-sdk"
)

func main() {
	rpc := begoniarpc.Default()
	rpc.Run("0.0.0.0:8080")
}

How to provide a service?

package main

import (
	"github.com/MashiroC/begonia-rpc/entity"
	"github.com/MashiroC/begonia-rpc/sdk"
)

type MathService struct {
}

type HelloService struct {
}

func (s *MathService) Sum(a, b int) (res int) {
    return a + b
}


func (h *HelloService) Hello(name string) (res string) {
	return "Hello " + name
}

func main() {
	cli := begonia.Default(":8080")
	cli.Sign("Hello", &HelloService{})
	cli.Sign("Math",&MathService{})
	cli.KeepConnect()
}

And How to call remote function?

package main

import (
	"fmt"
	"github.com/MashiroC/begonia-rpc/entity"
	"github.com/MashiroC/begonia-rpc/sdk"
)

func main() {
    
    // get a begonia client
	cli := begonia.Default(":8080")
	
    // get a service
    helloService := cli.Service("Hello")
    
    // get a sync Function
    hello := helloService.FunSync("Hello")
    
    // call it!
    res, err := hello("MashiroC")
    
    fmt.Println(res, err)
    // Hello Mashiroc <nil>
    
   
    // get a async function
    helloAsync := helloService.FunAsync("Hello")

    // call it too!
    helloAsync(func(res interface{}, err error) {
        fmt.Println(res,err)
    	}, "MashiroC")
    
}

Run

this is rpc center, if you want to provide a service, please use sdk.

$ go build -o rpccenter ./cmd/server/main.go
$ ./rpccenter

or

$ go run ./cmd/server/main.go

Release History

0.1.0

Proof-of-concept code

begonia-rpc's People

Contributors

mashiroc avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.