dogerpc

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

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

Go to latest
Published: Feb 18, 2022 License: BSL-1.0 Imports: 11 Imported by: 0

README

සුකුමාලි වම්සහේලිහෙලේ මන්මදොරි

Usage

go get shaneumayanga.com/dogerpc

Server

    package main
    
    import (
        "net/http"

        "github.com/gin-gonic/gin"
        "shaneumayanga.com/dogerpc"
    )

    type TextStream struct {
        Chars []string
    }

    func (i *TextStream) HandleTextStream(in map[string]interface{}) []string {
        newChar := in["Char"].(string)
        i.Chars = append(i.Chars, newChar)
        return i.Chars
    }

    var dogerpcServer = dogerpc.NewDogeServer()
    var doge = dogerpcServer.GetDOGE()

    func init() {
        doge.Register(new(TextStream))
    }

    func Conn(c *gin.Context) {
        dogerpcServer.ServeConn(c.Writer, c.Request)
    }

    func main() {
        r := gin.New()
        r.GET("/ws", Conn)
        svc := &http.Server{
            Addr:    ":8080",
            Handler: r,
        }
        svc.ListenAndServe()
    }


Client

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Doge</title>
    </head>
    <body>
        <input id="charIn"/>
        <div id="charout"></div>
        <script>
            var charIn = document.getElementById("charIn");
            var charout = document.getElementById("charout");
            var ws = new WebSocket("ws://localhost:8080/ws")
            ws.onopen = (e)=>{
                alert("Connection opened")
            }
            ws.onmessage =(e)=>{
                charout.innerHTML+=e.data;
            }
            charIn.addEventListener('keyup',(e)=>{
                var data = {
                    "method":"HandleTextStream",
                    "params":{"Char":charIn.value},
                }
                ws.send(JSON.stringify(data));
            })
        </script>
    </body>
    </html>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TrimSpace

func TrimSpace(str string) string

Types

type Client

type Client struct {
	ID   string
	Conn net.Conn
}

func (*Client) Close

func (c *Client) Close()

func (*Client) GetAddress

func (c *Client) GetAddress() string

type Connections

type Connections struct {
	Connections map[string]*Client
	Mu          *sync.Mutex
}

func (*Connections) Add

func (c *Connections) Add(conn *Client)

func (*Connections) BroadCast

func (c *Connections) BroadCast(v interface{}, methodName string)

func (*Connections) Remove

func (c *Connections) Remove(id string)

type DogeRPC

type DogeRPC struct {
	Trie *Trie
}

func (*DogeRPC) Call

func (dRPC *DogeRPC) Call(methodName string, in interface{}) []reflect.Value

Method name and input parameters

func (*DogeRPC) GetMethodByName

func (dRPC *DogeRPC) GetMethodByName(mname string) *Method

func (*DogeRPC) Register

func (dRPC *DogeRPC) Register(m interface{})

type Method

type Method struct {
	Method     reflect.Method
	Params     reflect.Type
	MethodType reflect.Value
}

type Node

type Node struct {
	// contains filtered or unexported fields
}

type Server

type Server struct {
	DogeRPC *DogeRPC
}

func NewDogeServer

func NewDogeServer() *Server

func (*Server) GetDOGE

func (s *Server) GetDOGE() *DogeRPC

func (*Server) ServeConn

func (s *Server) ServeConn(w http.ResponseWriter, r *http.Request) error

type ServerRequest

type ServerRequest struct {
	Method      string      `json:"method"`
	InputParams interface{} `json:"params"`
}

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

func NewTrie

func NewTrie() *Trie

Jump to

Keyboard shortcuts

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