for go
This commit is contained in:
parent
1a5225ef6f
commit
b4edfd7585
7 changed files with 62 additions and 11 deletions
|
@ -6,6 +6,10 @@ end_of_line = lf
|
|||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.go]
|
||||
indent_style = tab
|
||||
indent_size = 2
|
||||
|
||||
[*.nix]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
|
|
@ -9,15 +9,21 @@ defmodule PrymnWeb.AgentChannel do
|
|||
{:ok, socket}
|
||||
end
|
||||
|
||||
# Channels can be used in a request/response fashion
|
||||
# by sending replies to requests from the client
|
||||
@impl true
|
||||
def handle_in("ping", payload, socket) do
|
||||
{:reply, {:ok, payload}, socket}
|
||||
end
|
||||
|
||||
def handle_in("binary", {:binary, data}, socket) do
|
||||
dbg(data)
|
||||
def handle_in(event, _payload, socket) do
|
||||
dbg(event)
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
# Channels can be used in a request/response fashion
|
||||
# by sending replies to requests from the client
|
||||
# @impl true
|
||||
# def handle_in("ping", payload, socket) do
|
||||
# {:reply, {:ok, payload}, socket}
|
||||
# end
|
||||
|
||||
# def handle_in("binary", {:binary, data}, socket) do
|
||||
# dbg(data)
|
||||
# {:noreply, socket}
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
pkgs.elixir
|
||||
pkgs.elixir-ls
|
||||
pkgs.rustToolchain
|
||||
pkgs.natscli
|
||||
pkgs.go
|
||||
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.inotify-tools ];
|
||||
|
||||
services.postgres = {
|
||||
|
@ -52,8 +52,6 @@
|
|||
initialScript = "CREATE USER postgres SUPERUSER;";
|
||||
};
|
||||
|
||||
processes.nats-server.exec = "${pkgs.nats-server}/bin/nats-server -c ./agent/server.conf";
|
||||
|
||||
enterShell = ''
|
||||
echo happy deving
|
||||
'';
|
||||
|
|
14
goagent/cmd/agent/main.go
Normal file
14
goagent/cmd/agent/main.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.nikos.gg/prymn/prymn/goagent/pkg/gophx"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := gophx.Connect()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
5
goagent/go.mod
Normal file
5
goagent/go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module git.nikos.gg/prymn/prymn/goagent
|
||||
|
||||
go 1.21.5
|
||||
|
||||
require nhooyr.io/websocket v1.8.10 // indirect
|
2
goagent/go.sum
Normal file
2
goagent/go.sum
Normal file
|
@ -0,0 +1,2 @@
|
|||
nhooyr.io/websocket v1.8.10 h1:mv4p+MnGrLDcPlBoWsvPP7XCzTYMXP9F9eIGoKbgx7Q=
|
||||
nhooyr.io/websocket v1.8.10/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=
|
22
goagent/pkg/gophx/channel.go
Normal file
22
goagent/pkg/gophx/channel.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package gophx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"nhooyr.io/websocket"
|
||||
)
|
||||
|
||||
func Connect() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
|
||||
c, _, err := websocket.Dial(ctx, "ws://localhost:4000/agent/websocket?vsn=2.0.0", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Ping(ctx)
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue