rsocket_json_requests

package module
v0.0.0-...-d635deb Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2025 License: MIT Imports: 11 Imported by: 2

README

The objective of this project is create a wrapper of RSocket for Golang for JSON payloads and triggering methods on the server side, like a HTTP Route (a web request in gorilla, for example).

Example Server:

package main

import (
	"fmt"
	"rsocket_json_requests"
)

func main() {
	rsocket_json_requests.AppendFunctionHandler("execute_something", execute_something)
	rsocket_json_requests.AppendFunctionHandler("dont_execute_something", dont_execute_something)
	// add the path to your TLS certificate and key here
	//	rsocket_json_requests.SetTLSConfig("cert.pem", "key.pem")
	rsocket_json_requests.ServeCalls()
}

func execute_something(payload interface{}) interface{}{
	fmt.Println("execute_something")
	fmt.Println(payload)
	return payload
}


func dont_execute_something(payload interface{}) interface{}{
	fmt.Println("dont_execute_something")
	fmt.Println(payload)
	return payload
}


Example Client:

package main

import (
	"fmt"
	"rsocket_json_requests"
)

type peers_cont struct {
	Peers []peers `json:"peers"`
}

type peers struct {
	Name string `json:"name"`
	Address string `json:"address"`
}

func main(){
	list_peers := getObject() 
	//rsocket_json_requests.UseTLS()
	rsocket_json_requests.RequestConfigs("127.0.0.1", 7878)
	result, _ := rsocket_json_requests.RequestJSON("execute_something", list_peers)
	//You can (should) treat the error in case the second return of the function is not nil
	fmt.Println(result)
}

func getObject() peers_cont {
	var list_peers peers_cont
	var p peers
	p.Name = "Test"
	p.Address = "Street"
	list_peers.Peers = append(list_peers.Peers, p)

	var p1 peers
	p1.Name = "Test1"
	p1.Address = "Street1"
	list_peers.Peers = append(list_peers.Peers, p1)
	return list_peers
}

TODO:

  • ...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFunctionHandler

func AppendFunctionHandler(name string, function func(pload interface{}) interface{})

func CloseAllConn

func CloseAllConn()

func GetStatusConn

func GetStatusConn(name string) bool

func InitConn

func InitConn(name string, host string, port int) error

Starts singleton connection with server

Parameters:

  • name: unique name of the instance
  • host: the host or ip address
  • port: the port of the host

func RequestConfigs

func RequestConfigs(ip string, port int)

func RequestConfigsServer

func RequestConfigsServer(port int)

func RequestJSON

func RequestJSON(method string, json_content interface{}) (interface{}, error)

func RequestJSONNew

func RequestJSONNew(method string, json_content interface{}, instanceName string) (interface{}, error)

Creates a request with an existing connection to an instance.

Parameters:

  • method: name of the method to be called in the endpoint
  • json_content: parameters to be sent to the endpoint in JSON
  • name: unique name of the instance

func ServeCalls

func ServeCalls()

func SetTLSConfig

func SetTLSConfig(cert_path string, key_path string)

func UseTLS

func UseTLS()

Types

type ClientRsock

type ClientRsock struct {
	// Cli      rsocket.Client
	FreeList map[string]map[string]*ClientRsockDetails
	InUse    map[string]map[string]*ClientRsockDetails
	// contains filtered or unexported fields
}

func (*ClientRsock) AddRSockClient

func (cli *ClientRsock) AddRSockClient(client *rsocket.Client, instanceName string, hostName string, port int)

func (*ClientRsock) FreeExistingSocket

func (cli *ClientRsock) FreeExistingSocket(client *ClientRsockDetails) error

func (*ClientRsock) GetExistingOrNew

func (cli *ClientRsock) GetExistingOrNew(host string) (*ClientRsockDetails, error)

func (*ClientRsock) GetStatusConnection

func (cli *ClientRsock) GetStatusConnection(instanceName string) int

Shows status of the RSsock client with the Unique Instance Name. Returns 1 if there is a free connection, 2 if there is a connection in use and -1 if there is no connection

Parameters:

  • instanceName: unique name of the instance

type ClientRsockDetails

type ClientRsockDetails struct {
	// Cli      rsocket.Client
	Client       *rsocket.Client
	HostName     string
	InstanceName string
	InternalId   string
	Port         int
}

type FunctionName

type FunctionName struct {
	Function func(pload interface{}) interface{}
	Name     string
}

type GenericList

type GenericList struct {
	Method  string      `json:"method"`
	Payload interface{} `json:"payload"`
}

Jump to

Keyboard shortcuts

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