Skip to content

Commit c191893

Browse files
committed
initial commit
0 parents  commit c191893

File tree

6 files changed

+476
-0
lines changed

6 files changed

+476
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: go-codegen
2+
3+
on:
4+
push:
5+
paths:
6+
- 'oas_spec_definition/*.yaml'
7+
workflow_dispatch:
8+
inputs:
9+
reason:
10+
description: 'reason'
11+
required: false
12+
default: 'manual run'
13+
14+
jobs:
15+
run-go-codegen:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up JDK 1.8
20+
uses: actions/setup-java@v1
21+
with:
22+
java-version: 1.8
23+
- name: Set up Go
24+
uses: actions/setup-go@v2
25+
with:
26+
go-version: 1.16.6
27+
- name: Prepare for code formatting
28+
shell: bash
29+
run: go get golang.org/x/tools/cmd/goimports && which gofmt
30+
env:
31+
GO_POST_PROCESS_FILE: "gofmt -w"
32+
- name: Setup the latest openapi-generator-cli
33+
shell: bash
34+
run: curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > ./openapi-generator-cli && chmod u+x ./openapi-generator-cli
35+
- name: Execute go-server codegen
36+
run: ./openapi-generator-cli generate -i ./oas_spec_definition/go-postgres-sockets.yaml -g go-server -o ./server -ppackageName=api -psourceFolder=api --git-user-id=bebo-dot-dev --git-repo-id=go-postgres-sockets/server --enable-post-process-file
37+
- name: Format generated Go code
38+
shell: bash
39+
run: goimports -w -v ./ && cd ./server && go get ./... && go fmt ./... && cd ../client && go get ./... && go fmt ./...
40+
- name: Commit generated Go code
41+
shell: bash
42+
run: git config --global user.email "[email protected]" && git config --global user.name "Joe" && git fetch --all && git add -A && git commit -m "automated codegen commit" && git pull --rebase && git push

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# go-postgres-sockets
2+
3+
A proof of concept Go application that demonstrates the use of postgres NOTIFY (plpgsql pg_notify function) and LISTEN (Go postgres package *pq.Listener) in conjunction with https://github.com/gorilla/websocket.
4+
5+
In this POC, data changes applied within a postgres db table result in Go listening code receiving notification of the data change and the data change then broadcast to connected websocket clients.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
openapi: 3.0.0
3+
info:
4+
title: User API
5+
description: A notifications proof of concept API
6+
contact:
7+
8+
license:
9+
name: Apache 2.0
10+
url: http://www.apache.org/licenses/LICENSE-2.0.html
11+
version: 0.1.0
12+
servers:
13+
- url: http://localhost:8080
14+
description: localhost test endpoint
15+
tags:
16+
- name: Notifications API
17+
description: Notifications operations
18+
paths:
19+
/ping:
20+
get:
21+
tags:
22+
- Notifications API
23+
summary: tests this api
24+
description: returns the hostname of the server running this service
25+
operationId: ping
26+
responses:
27+
"201":
28+
description: server responded
29+
content:
30+
application/json:
31+
schema:
32+
$ref: '#/components/schemas/PingResponse'
33+
/addNotification:
34+
put:
35+
tags:
36+
- Notifications API
37+
summary: adds a new notification
38+
description: Adds a new notification to the system
39+
operationId: addNotification
40+
requestBody:
41+
description: the notification to add
42+
content:
43+
application/json:
44+
schema:
45+
$ref: '#/components/schemas/NotificationDetails'
46+
responses:
47+
"201":
48+
description: StatusCreated, notification created
49+
content:
50+
application/json:
51+
schema:
52+
$ref: '#/components/schemas/Id'
53+
"400":
54+
description: StatusBadRequest
55+
"500":
56+
description: ServerError
57+
components:
58+
schemas:
59+
PingResponse:
60+
required:
61+
- hostname
62+
type: object
63+
properties:
64+
hostname:
65+
type: string
66+
example: localhost
67+
NotificationDetails:
68+
required:
69+
- notificationType
70+
- notificationText
71+
type: object
72+
properties:
73+
notificationType:
74+
description: describes the type of notification (0 = none, 1 = email, 2 = sms, 3 = slack)
75+
type: integer
76+
example: 1
77+
notificationText:
78+
description: arbitrary notification data
79+
type: string
80+
example: some notification data
81+
Id:
82+
required:
83+
- id
84+
properties:
85+
id:
86+
description: the id of a new entity
87+
type: integer
88+
example: 123
89+
NotificationSocketMessage:
90+
required:
91+
- table
92+
- operation
93+
- data
94+
properties:
95+
table:
96+
description: describes the database table changed
97+
type: string
98+
example: 'notifications'
99+
operation:
100+
description: describes the database operation performed
101+
type: string
102+
example: 'INSERT'
103+
data:
104+
required:
105+
- id
106+
- notificationTypeId
107+
- createdTimestamp
108+
- notificationText
109+
- notificationType
110+
description : notification data
111+
type: object
112+
properties:
113+
id:
114+
description: the id of the row changed
115+
type: integer
116+
example: 6
117+
notificationTypeId:
118+
description: describes the type of notification (0 = none, 1 = email, 2 = sms, 3 = slack)
119+
type: integer
120+
example: 1
121+
createdTimestamp:
122+
description: the creation timestamp of the row
123+
type: string
124+
example: 01/01/2021
125+
notificationText:
126+
description: notification text data
127+
type: string
128+
example: some data
129+
notificationType:
130+
description: textual descriptor for notificationTypeId
131+
type: string
132+
example: email

postgres/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# postgres
2+
3+
[notifications_db_backup.sql](https://github.com/bebo-dot-dev/go-postgres-sockets/blob/main/postgres/notifications_db_backup.sql) is a plain text backup dump of a simple postgresql notifications database
4+
5+
This database was created and tested with "PostgreSQL 13.3 (Ubuntu 13.3-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit"
6+
7+
restore the database:
8+
`psql < notifications_db_backup.sql`
9+
10+
## db details
11+
12+
This notifications database contains 2 tables, 1 regular function and 1 trigger function:
13+
14+
### tables:
15+
16+
1. notification_type
17+
2. notifications (has notify_notification_changes() trigger function)
18+
19+
### function:
20+
21+
1. new_notification
22+
23+
### trigger function:
24+
25+
1. notify_notification_changes
26+
27+
28+
## function calls:
29+
30+
```
31+
SELECT public.new_notification(
32+
1,
33+
'notification text data here'
34+
)
35+
```
36+
37+
38+
## pgadmin
39+
![files](./pgadmin.png)

0 commit comments

Comments
 (0)