From e9af9bc115e0869570b9b79e1610b2bc08abe5a1 Mon Sep 17 00:00:00 2001 From: hozan23 <119854621+hozan23@users.noreply.github.com> Date: Thu, 13 Jun 2024 14:51:54 +0200 Subject: Create .github/workflows/go.yml --- .github/workflows/go.yml | 24 +++++++++++++++++ example.go | 70 ------------------------------------------------ example_test.go | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- 4 files changed, 95 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/go.yml delete mode 100644 example.go create mode 100644 example_test.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..1384017 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,24 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: Go + +on: [push, pull_request] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.22' + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... diff --git a/example.go b/example.go deleted file mode 100644 index b51bc24..0000000 --- a/example.go +++ /dev/null @@ -1,70 +0,0 @@ -package main - -import ( - "encoding/json" - "math/rand/v2" - "os" - "time" - - rpc "github.com/karyontech/karyon-go/jsonrpc/client" - log "github.com/sirupsen/logrus" -) - -type Pong struct{} - -func runNewClient() error { - config := rpc.RPCClientConfig{ - Addr: "ws://127.0.0.1:6000", - } - - client, err := rpc.NewRPCClient(config) - if err != nil { - return err - } - defer client.Close() - - subID, ch, err := client.Subscribe("Calc.log_subscribe", nil) - if err != nil { - return err - } - log.Infof("Subscribed successfully: %d\n", subID) - - go func() { - for notification := range ch { - log.Infof("Receive new notification: %s\n", notification) - } - }() - - for { - millisecond := rand.IntN(2000-500) + 500 - time.Sleep(time.Duration(millisecond) * time.Millisecond) - result, err := client.Call("Calc.ping", nil) - if err != nil { - return err - } - - pongMsg := Pong{} - err = json.Unmarshal(*result, &pongMsg) - if err != nil { - return err - } - } - -} - -func main() { - lvl, ok := os.LookupEnv("LOG_LEVEL") - if !ok { - lvl = "debug" - } - ll, err := log.ParseLevel(lvl) - if err != nil { - ll = log.DebugLevel - } - log.SetLevel(ll) - - err = runNewClient() - if err != nil { - log.Fatal(err) - } -} diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..ca4a642 --- /dev/null +++ b/example_test.go @@ -0,0 +1,70 @@ +package karyongo + +import ( + "encoding/json" + "math/rand/v2" + "os" + "time" + + rpc "github.com/karyontech/karyon-go/jsonrpc/client" + log "github.com/sirupsen/logrus" +) + +type Pong struct{} + +func runNewClient() error { + config := rpc.RPCClientConfig{ + Addr: "ws://127.0.0.1:6000", + } + + client, err := rpc.NewRPCClient(config) + if err != nil { + return err + } + defer client.Close() + + subID, ch, err := client.Subscribe("Calc.log_subscribe", nil) + if err != nil { + return err + } + log.Infof("Subscribed successfully: %d\n", subID) + + go func() { + for notification := range ch { + log.Infof("Receive new notification: %s\n", notification) + } + }() + + for { + millisecond := rand.IntN(2000-500) + 500 + time.Sleep(time.Duration(millisecond) * time.Millisecond) + result, err := client.Call("Calc.ping", nil) + if err != nil { + return err + } + + pongMsg := Pong{} + err = json.Unmarshal(*result, &pongMsg) + if err != nil { + return err + } + } + +} + +func main() { + lvl, ok := os.LookupEnv("LOG_LEVEL") + if !ok { + lvl = "debug" + } + ll, err := log.ParseLevel(lvl) + if err != nil { + ll = log.DebugLevel + } + log.SetLevel(ll) + + err = runNewClient() + if err != nil { + log.Fatal(err) + } +} diff --git a/go.mod b/go.mod index c2c84a0..ae3fdc3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/karyontech/karyon-go -go 1.22.3 +go 1.22 require ( github.com/gorilla/websocket v1.5.1 -- cgit v1.2.3