Skip to content

karyontech/karyon-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Karyon-go

karyon jsonrpc client, written in go.

Install

    go get github.com/karyontech/karyon-go 

Example

package main

import (
	"fmt"
	"log/slog"
	"os"
	"time"

	rpc "github.com/karyontech/karyon-go/jsonrpc/client"
)

func main() {

	config := rpc.RPCClientConfig{
		Addr: "ws://localhost:7000/",
		// Addr: "tcp://localhost:7000/",
	}

	client, err := rpc.NewRPCClient(config)
	if err != nil {
		slog.Error("Create a new rpc client", "error", err)
		os.Exit(1)
	}

	defer client.Close()

	sub, err := client.Subscribe("Calc.log_subscribe", nil)
	if err != nil {
		slog.Error("Subscribe to log_subscribe", "error", err)
		os.Exit(1)
	}
	fmt.Printf("Subscribed successfully: %d\n", sub.ID)

	go func() {
		for notification := range sub.Recv() {
			fmt.Printf("Receive a new notification: %s\n", notification)
		}
	}()

	time.Sleep(time.Second * 10)

	msg, err := client.Call("Calc.ping", nil)
	if err != nil {
		slog.Error("Call ping method", "error", err)
		os.Exit(1)
	}

	fmt.Printf("Receive a pong msg: %s", msg)

}

License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

Contributions

Contributions are welcome! Please open an issue or submit a pull request.

About

karyon jsonrpc client, written in go

Resources

License

Stars

Watchers

Forks

Packages

No packages published