Skip to content

Commit 3f2015d

Browse files
committed
migrate from goserve to example project
0 parents  commit 3f2015d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+6551
-0
lines changed

.dockerignore

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Binaries
2+
/server
3+
/server.exe
4+
5+
# Vendor directory (if not using Go modules)
6+
vendor/
7+
8+
# OS-specific files
9+
*.exe
10+
*.dll
11+
*.so
12+
*.dylib
13+
14+
# Test output
15+
*.out
16+
17+
# Logs
18+
*.log
19+
20+
# Coverage files
21+
*.cover
22+
*.coverage
23+
*.cov
24+
25+
# Build directories
26+
bin/
27+
obj/
28+
build/
29+
dist/
30+
31+
# IDE/editor directories and files
32+
.vscode/
33+
.idea/
34+
*.swp
35+
*~
36+
37+
# Git
38+
.git/
39+
.gitignore
40+
41+
# Docker
42+
.dockerignore
43+
Dockerfile
44+
45+
# Dependency management files
46+
go.sum
47+
48+
# Any other files you want to exclude
49+
.DS_Store
50+
.github/
51+
.tools/
52+
logs/
53+
*.md

.editorconfig

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
11+
# Go files
12+
[*.go]
13+
indent_style = tab
14+
indent_size = 2
15+
16+
# JavaScript files
17+
[*.js]
18+
indent_style = space
19+
indent_size = 2
20+
21+
# Markdown files
22+
[*.md]
23+
max_line_length = 80
24+
trim_trailing_whitespace = false
25+
26+
# JSON files
27+
[*.json]
28+
indent_style = space
29+
indent_size = 2
30+
31+
# YAML files
32+
[*.yml, *.yaml]
33+
indent_style = space
34+
indent_size = 2

.env.example

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# debug, release, test
2+
GO_MODE=debug
3+
4+
SERVER_HOST=0.0.0.0
5+
SERVER_PORT=8080
6+
7+
DB_HOST=mongo
8+
DB_PORT=27017
9+
DB_NAME=goserver-dev-db
10+
DB_USER=goserver-dev-db-user
11+
DB_USER_PWD=changeit
12+
DB_MIN_POOL_SIZE=2
13+
DB_MAX_POOL_SIZE=5
14+
DB_QUERY_TIMEOUT_SEC=60
15+
DB_ADMIN=admin
16+
DB_ADMIN_PWD=changeit
17+
18+
REDIS_HOST=redis
19+
REDIS_PORT=6379
20+
REDIS_PASSWORD=changeit
21+
22+
# 2 DAYS: 172800 Sec
23+
ACCESS_TOKEN_VALIDITY_SEC=172800
24+
# 7 DAYS: 604800 Sec
25+
REFRESH_TOKEN_VALIDITY_SEC=604800
26+
TOKEN_ISSUER=api.goserve.afteracademy.com
27+
TOKEN_AUDIENCE=goserve.afteracademy.com
28+
29+
RSA_PRIVATE_KEY_PATH="keys/private.pem"
30+
RSA_PUBLIC_KEY_PATH="keys/public.pem"

.extra/docs/goserve-banner.png

10.9 KB
Loading

.extra/docs/goserve-cover.png

18.4 KB
Loading

.extra/docs/request-flow.svg

Lines changed: 4 additions & 0 deletions
Loading

.extra/setup/init-mongo.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
function seed(dbName, user, password) {
2+
db = db.getSiblingDB(dbName);
3+
db.createUser({
4+
user: user,
5+
pwd: password,
6+
roles: [{ role: "readWrite", db: dbName }],
7+
});
8+
9+
db.createCollection("api_keys");
10+
db.createCollection("roles");
11+
12+
db.api_keys.insert({
13+
key: "1D3F2DD1A5DE725DD4DF1D82BBB37",
14+
permissions: ["GENERAL"],
15+
comments: ["To be used by the xyz vendor"],
16+
version: 1,
17+
status: true,
18+
createdAt: new Date(),
19+
updatedAt: new Date(),
20+
});
21+
22+
db.roles.insertMany([
23+
{
24+
code: "LEARNER",
25+
status: true,
26+
createdAt: new Date(),
27+
updatedAt: new Date(),
28+
},
29+
{
30+
code: "AUTHOR",
31+
status: true,
32+
createdAt: new Date(),
33+
updatedAt: new Date(),
34+
},
35+
{
36+
code: "EDITOR",
37+
status: true,
38+
createdAt: new Date(),
39+
updatedAt: new Date(),
40+
},
41+
{
42+
code: "ADMIN",
43+
status: true,
44+
createdAt: new Date(),
45+
updatedAt: new Date(),
46+
},
47+
]);
48+
49+
db.users.insert({
50+
name: "Admin",
51+
52+
password: "$2a$10$psWmSrmtyZYvtIt/FuJL1OLqsK3iR1fZz5.wUYFuSNkkt.EOX9mLa", // hash of password: changeit
53+
roles: db.roles
54+
.find({})
55+
.toArray()
56+
.map((role) => role._id),
57+
status: true,
58+
createdAt: new Date(),
59+
updatedAt: new Date(),
60+
});
61+
}
62+
63+
seed("goserver-prod-db", "goserver-prod-db-user", "changeit");
64+
seed("goserver-dev-db", "goserver-dev-db-user", "changeit");
65+
seed("goserver-test-db", "goserver-test-db-user", "changeit");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Docker Compose CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
- name: Create .env
16+
run: cp .env.example .env
17+
- name: Create .test.env
18+
run: cp .test.env.example .test.env
19+
- name: Create pems
20+
run: go run .tools/rsa/keygen.go
21+
- name: Build docker images
22+
run: docker compose build
23+
- name: Run docker images
24+
run: docker compose up -d
25+
- name: Run tests
26+
run: docker exec -t goserver go test -v ./...
27+
- name: Clean up
28+
if: success() || failure()
29+
run: docker compose down --rmi all -v --remove-orphans

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
.DS_Store
5+
# Binaries for programs and plugins
6+
*.exe
7+
*.exe~
8+
*.dll
9+
*.so
10+
*.dylib
11+
12+
# Test binary, built with `go test -c`
13+
*.test
14+
!Dockerfile.test
15+
16+
# Output of the go coverage tool, specifically when used with LiteIDE
17+
*.out
18+
19+
# Dependency directories (remove the comment below to include it)
20+
# vendor/
21+
22+
# Go workspace file
23+
go.work
24+
go.work.sum
25+
26+
# Environment varibles
27+
*.env
28+
*.env.test
29+
30+
#keys
31+
keys/*
32+
!keys/*.md
33+
!keys/*.txt
34+
*.pem
35+
36+
__debug*
37+
38+
build

.test.env.example

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# debug, release, test
2+
GO_MODE=test
3+
4+
DB_HOST=mongo
5+
DB_PORT=27017
6+
DB_NAME=goserver-test-db
7+
DB_USER=goserver-test-db-user
8+
DB_USER_PWD=changeit
9+
DB_MIN_POOL_SIZE=2
10+
DB_MAX_POOL_SIZE=5
11+
DB_QUERY_TIMEOUT_SEC=60
12+
DB_ADMIN=admin
13+
DB_ADMIN_PWD=changeit
14+
15+
REDIS_HOST=redis
16+
REDIS_PORT=6379
17+
REDIS_PASSWORD=changeit
18+
19+
# 2 DAYS: 172800 Sec
20+
ACCESS_TOKEN_VALIDITY_SEC=172800
21+
# 7 DAYS: 604800 Sec
22+
REFRESH_TOKEN_VALIDITY_SEC=604800
23+
TOKEN_ISSUER=api.goserve.afteracademy.com
24+
TOKEN_AUDIENCE=goserve.afteracademy.com
25+
26+
RSA_PRIVATE_KEY_PATH="../keys/private.pem"
27+
RSA_PUBLIC_KEY_PATH="../keys/public.pem"

0 commit comments

Comments
 (0)