Skip to content

Commit

Permalink
Merge pull request #88 from emidev98/master
Browse files Browse the repository at this point in the history
feat: basic relayer
  • Loading branch information
mattn authored Oct 22, 2023
2 parents 361f745 + 22b14a6 commit f161210
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Relayer",
"type": "go",
"request": "launch",
"mode": "debug",
"asRoot": true,
"program": "${workspaceFolder}/examples/basic",
"cwd": "${workspaceFolder}/examples/basic",
"env": {
"POSTGRESQL_DATABASE" : "postgres://nostr:nostr@localhost:5432/nostr?sslmode=disable"
}
}
]
}
4 changes: 2 additions & 2 deletions examples/basic/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM golang:1.18
FROM golang:1.21.1

WORKDIR /go/src/app
COPY ./ .

RUN go get -d -v ./...
RUN go install -v ./...
RUN cd basic && make
RUN cd examples/basic && make
2 changes: 2 additions & 0 deletions examples/basic/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
relayer-basic: $(shell find .. -name "*.go")
CC=$$(which musl-gcc) go build -ldflags='-s -w -linkmode external -extldflags "-static"' -o ./relayer-basic

start: POSTGRESQL_DATABASE=postgres://nostr:nostr@localhost:5432/nostr?sslmode=disable go run main.go
26 changes: 21 additions & 5 deletions examples/basic/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ services:

relay:
build:
context: ../
dockerfile: ./basic/Dockerfile
context: ../../
dockerfile: ./examples/basic/Dockerfile
environment:
PORT: 2700
PORT: 7447
POSTGRESQL_DATABASE: postgres://nostr:nostr@postgres:5432/nostr?sslmode=disable
depends_on:
postgres:
condition: service_healthy
ports:
- 2700:2700
command: "./basic/relayer-basic"
- 2700:7447
command: "./examples/basic/relayer-basic"

postgres:
image: postgres
Expand All @@ -30,3 +30,19 @@ services:
interval: 10s
timeout: 5s
retries: 5

pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
restart: unless-stopped
depends_on:
- postgres
ports:
- "5050:80"
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: nostr
volumes:
- pgadmin:/var/lib/pgadmin
volumes:
pgadmin:
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/fiatjaf/relayer/v2

go 1.18
go 1.21

require (
github.com/PuerkitoBio/goquery v1.8.0
Expand Down
3 changes: 2 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ func challenge(conn *websocket.Conn) *WebSocket {

func (s *Server) doEvent(ctx context.Context, ws *WebSocket, request []json.RawMessage, store Storage) string {
advancedDeleter, _ := store.(AdvancedDeleter)
latestInex := len(request) - 1

// it's a new event
var evt nostr.Event
if err := json.Unmarshal(request[1], &evt); err != nil {
if err := json.Unmarshal(request[latestInex], &evt); err != nil {
return "failed to decode event: " + err.Error()
}

Expand Down

0 comments on commit f161210

Please sign in to comment.