gonameko

package module
v0.0.2-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 5 Imported by: 1

README

gonameko

A Golang implementation of Nameko

Usage

go get -u github.com/iamdavidzeng/gonameko

client pattern

package main

import (
	"fmt"

	"github.com/iamdavidzeng/gonameko"
)

func main() {
	client := gonameko.Client{
		RabbitHostname: "localhost",
		RabbitUser:     "guest",
		RabbitPass:     "guest",
		RabbitPort:     5672,
		ContentType:    "application/json",
	}
	client.Setup()

	response, err := client.Call(gonameko.RPCRequestParam{
		Service:  "locations",
		Function: "health_check",
		Payload: gonameko.RPCPayload{
			Args:   []string{},
			Kwargs: map[string]string{},
		},
	})
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(response)
	}
}

server pattern

package main

import "github.com/iamdavidzeng/gonameko"

func main() {
	server := gonameko.Server{
		Name:           "gonameko",
		RabbitHostname: "localhost",
		RabbitUser:     "guest",
		RabbitPass:     "guest",
		RabbitPort:     5672,
		ContentType:    "application/json",
	}
	server.Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FailOnError

func FailOnError(err error, msg string)

Types

type Client

type Client struct {
	RabbitHostname string
	RabbitUser     string
	RabbitPass     string
	RabbitPort     int64
	ContentType    string

	Conn *Connection
}

Client use to initiate a go nameko client

func (*Client) Call

func (c *Client) Call(p RPCRequestParam) (interface{}, error)

Call publish a message to nameko service and return corresponding response

func (*Client) Setup

func (c *Client) Setup()

type Connection

type Connection struct {
	Name           string
	RabbitHostname string
	RabbitUser     string
	RabbitPass     string
	RabbitPort     int64
	ContentType    string
	// contains filtered or unexported fields
}

func (*Connection) Call

func (c *Connection) Call(p RPCRequestParam) (interface{}, error)

func (*Connection) Declare

func (c *Connection) Declare()

func (*Connection) Serve

func (c *Connection) Serve(name string)

type Error

type Error struct {
	Type, Value string
}

Error represent gonamekoclient customize error

func (*Error) Error

func (e *Error) Error() string

type RPCError

type RPCError struct {
	ExcArgs string `json:"exc_args"`
	ExcPath string `json:"exc_path"`
	ExcType string `json:"exc_type"`
	Value   string `json:"value"`
}

RPCError capture exception from nameko service

func (*RPCError) Error

func (e *RPCError) Error() string

type RPCPayload

type RPCPayload struct {
	Args   []string          `json:"args"`
	Kwargs map[string]string `json:"kwargs"`
}

RPCPayload define arguments accept by nameko service

type RPCRequestParam

type RPCRequestParam struct {
	Service, Function string
	Payload           RPCPayload
}

RPCRequestParam define nameko service and function, arguments

type RPCResponse

type RPCResponse struct {
	Result interface{}       `json:"result"`
	Err    map[string]string `json:"error"`
}

RPCResponse Use to parse resposne from nameko service

type Server

type Server struct {
	Name string

	RabbitHostname string
	RabbitUser     string
	RabbitPass     string
	RabbitPort     int64
	ContentType    string

	Conn *Connection
}

func (*Server) Run

func (s *Server) Run()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL