route

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2020 License: MIT Imports: 2 Imported by: 0

README

rsocket-router

Tool for rsocket-go implementation which help easy create routes for RSocket using composite metadata and make your code pretty.

Features

  • Simple
  • Minimal configuration

Usage

main.go

package echo

import (
	"context"
	"fmt"
	"github.com/vitdevelop/rsocket-route"
	"github.com/rsocket/rsocket-go"
	"github.com/rsocket/rsocket-go/payload"
)

func init() {
	err := route.Add(Routings)

	if err != nil {
		fmt.Printf("%v\n", err)
	}
}

func main() {
	err := rsocket.Receive().
		Resume().
		Acceptor(func(setup payload.SetupPayload, sendingSocket rsocket.CloseableRSocket) (rsocket.RSocket, error) {
			return rsocket.NewAbstractSocket(route.GetHandlers()...), nil
		}).
		Transport("tcp://127.0.0.1:8080").
		Serve(context.Background())
	panic(err)
}

controller.go

package echo

import (
	"github.com/rsocket/rsocket-go/payload"
	"github.com/rsocket/rsocket-go/rx"
	"github.com/rsocket/rsocket-go/rx/flux"
	"github.com/rsocket/rsocket-go/rx/mono"
)

var Routings = make(map[string]interface{})

func init() {
	Routings["/request-response"] = echoRR
	Routings["/request-stream"] = echoRS
	Routings["/request-channel"] = echoRC
}

func echoRR(msg payload.Payload) mono.Mono {
	return mono.Just(msg)
}

func echoRS(msg payload.Payload) flux.Flux {
	return flux.Just(msg)
}

func echoRC(msgs rx.Publisher) flux.Flux {
	return msgs.(flux.Flux)
}
Dependencies

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(routes map[string]interface{}) error

func GetHandlers

func GetHandlers() []rsocket.OptAbstractSocket

Types

This section is empty.

Directories

Path Synopsis
examples
internal

Jump to

Keyboard shortcuts

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