transports

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: MIT Imports: 6 Imported by: 0

README

Golang transports

1.TCP

Inside there is TCP router for handling tcp connection from clients written in different languages(tested with node.js client)

1.1 handleSimpleConnection

Import module and use for routing tcp connections like this:


/** in package */
type TContext struct {
	Conn    net.Conn
	Options string
	Data    []byte
}

routes := map[string]func(tc transports.TContext){
		"calculate":         controllers.CalculationGo,
}

transports.TCPRouter(ln, routes)

routes - is map[string]func(tc transports.TContext){} that describe controllers for "handleSimpleConnection" function

ln - is instance of net.Listener

ln, err := net.Listen("tcp", ":4444")
Example of incomming message that can process handleSimpleConnection:
 "{LENGTHOFBUFFER}#"{
           pattern: string,
           data: any,
       }""

In you only specify buffer length and "#" separator {LENGTHOFBUFFER}

1.2 handleStreamConnection

This method start to execute when you specify additional params in beginning of tcp stream. It helps to process files to golang server

Example of string and buffer data that sends from client server to golang server:

message_length={LENGTHOFBUFFER}@{FILEOPTIONS}# - {METADATA} in string representation (you need to convert it to buffer)

{METADATA}{BUFFER} - you need to concat two buffers into one

{LENGTHOFBUFFER} - its length of buffer

{FILEOPTIONS} - file options = { fieldname string, originalname string, encoding string, mimetype string, size int, }

@ - separator between {LENGTHOFBUFFER} and {FILEOPTIONS}

# - separator between message meta and {BUFFER}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TCPRouter

func TCPRouter(ln net.Listener, routesDefault RouterMap)

* Receive net.Listener and map with routes and appropriate function handler

Types

type RequestData

type RequestData interface {
}

type RouterMap

type RouterMap map[string]func(tc TContext)
  • RouterMap is a type for keys(patterns) and appropriate function handler receive: conn - connection options - specific for some function handler data - in byte slice. Unmarshal in appropriate function handler

type TContext added in v1.1.3

type TContext struct {
	Conn    net.Conn
	Options string
	Data    []byte
}

Jump to

Keyboard shortcuts

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