Skip to content

Commit 80cd1ce

Browse files
authored
v1.0.0 #11
2 parents 473ba4b + 8e9fd08 commit 80cd1ce

File tree

103 files changed

+8634
-0
lines changed

Some content is hidden

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

103 files changed

+8634
-0
lines changed

.github/workflows/cd.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- release/*
7+
workflow_dispatch:
8+
9+
jobs:
10+
test:
11+
name: Test Runner
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout Code
15+
uses: actions/checkout@v3
16+
- name: Set Up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version-file: go.mod
20+
- name: Run Tests
21+
run: go test -v ./...
22+
build:
23+
name: Build Runner
24+
runs-on: ubuntu-latest
25+
needs: test
26+
steps:
27+
- name: Checkout Code
28+
uses: actions/checkout@v3
29+
- name: Set Up Go
30+
uses: actions/setup-go@v4
31+
with:
32+
go-version-file: go.mod
33+
- name: Run Build
34+
run: go build -v ./...
35+
deploy:
36+
name: Deploy Runner
37+
runs-on: ubuntu-latest
38+
needs: build
39+
steps:
40+
- name: Checkout Code
41+
uses: actions/checkout@v3
42+
- name: Login to DockerHub
43+
uses: docker/[email protected]
44+
with:
45+
username: ${{ secrets.DOCKERHUB_USERNAME }}
46+
password: ${{ secrets.DOCKERHUB_TOKEN }}
47+
- name: Set Image Version
48+
run: |
49+
echo IMAGE_VERSION=$(echo ${{ github.ref_name }} | sed "s/^release\///") >> $GITHUB_ENV
50+
echo "Image Version - $IMAGE_VERSION"
51+
- name: Push Image
52+
uses: docker/[email protected]
53+
with:
54+
context: .
55+
push: true
56+
build-args: VERSION=${{ env.IMAGE_VERSION }}
57+
tags: ${{ vars.DOCKERHUB_REPOSITORY }}:${{ env.IMAGE_VERSION }}

.github/workflows/ci.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: CI Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- hotfix/**
8+
- develop
9+
- feature/**
10+
- bugfix/**
11+
workflow_dispatch:
12+
13+
jobs:
14+
version:
15+
name: Version Runner
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout Code
19+
uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
- name: Install GitVersion
23+
uses: gittools/actions/gitversion/setup@v0
24+
with:
25+
versionSpec: 5.x
26+
preferLatestVersion: true
27+
- name: Set Version
28+
id: gitversion
29+
uses: gittools/actions/gitversion/execute@v0
30+
with:
31+
useConfigFile: true
32+
- name: Show Version
33+
run: |
34+
echo "Version: v${{ steps.gitversion.outputs.majorMinorPatch }}-${{ steps.gitversion.outputs.branchName }}"
35+
test:
36+
name: Test Runner
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout Code
40+
uses: actions/checkout@v3
41+
- name: Set Up Go
42+
uses: actions/setup-go@v4
43+
with:
44+
go-version-file: go.mod
45+
- name: Run Tests
46+
run: go test -v ./...
47+
build:
48+
name: Build Runner
49+
runs-on: ubuntu-latest
50+
needs: test
51+
steps:
52+
- name: Checkout Code
53+
uses: actions/checkout@v3
54+
- name: Set Up Go
55+
uses: actions/setup-go@v4
56+
with:
57+
go-version-file: go.mod
58+
- name: Run Build
59+
run: go build -v ./...

.mockery.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
disable-version-string: True
2+
with-expecter: True
3+
dir: "test/mocks/"
4+
outpkg: "mocks"
5+
filename: "{{.InterfaceName}}Mock.go"
6+
mockname: "{{.InterfaceName}}Mock"
7+
packages:
8+
github.com/sesaquecruz/go-chat-api/internal/domain/gateway:
9+
config:
10+
all: True
11+
github.com/sesaquecruz/go-chat-api/internal/domain/repository:
12+
config:
13+
all: True

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:1.21.0-alpine3.18 as build
2+
RUN apk --no-cache add ca-certificates
3+
WORKDIR /app
4+
COPY . .
5+
RUN go mod download
6+
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o build/chat cmd/chat/main.go
7+
8+
FROM scratch
9+
WORKDIR /app
10+
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
11+
COPY --from=build /app/build/chat .
12+
CMD [ "./chat" ]

GitVersion.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
mode: MainLine
2+
3+
major-version-bump-message: '^(feat|fix|refactor|revert)!:'
4+
minor-version-bump-message: '^(feat):'
5+
patch-version-bump-message: '^(fix|refactor|revert|test|build|chore):'
6+
7+
branches:
8+
main:
9+
regex: ^main$
10+
mode: ContinuousDeployment
11+
tag: useBranchName
12+
increment: None
13+
prevent-increment-of-merged-branch-version: true
14+
is-mainline: true
15+
hotfix:
16+
regex: ^hotfix/
17+
mode: ContinuousDelivery
18+
tag: useBranchName
19+
increment: None
20+
prevent-increment-of-merged-branch-version: true
21+
source-branches: [ 'main' ]
22+
develop:
23+
regex: ^develop$
24+
mode: ContinuousDelivery
25+
tag: useBranchName
26+
increment: None
27+
prevent-increment-of-merged-branch-version: true
28+
source-branches: [ 'main' ]
29+
feature:
30+
regex: ^feature/
31+
mode: ContinuousDelivery
32+
tag: useBranchName
33+
increment: None
34+
prevent-increment-of-merged-branch-version: true
35+
source-branches: [ 'develop' ]
36+
bugfix:
37+
regex: ^bugfix/
38+
mode: ContinuousDelivery
39+
tag: useBranchName
40+
increment: None
41+
prevent-increment-of-merged-branch-version: true
42+
source-branches: [ 'develop', 'release' ]
43+
release:
44+
regex: ^release/
45+
mode: ContinuousDelivery
46+
tag: useBranchName
47+
increment: None
48+
prevent-increment-of-merged-branch-version: true
49+
source-branches: [ 'develop' ]

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
update_dependency_injection:
4+
@if !command -v wire >/dev/null 2>&1 ; then \
5+
echo "Go Wire is not installed. Installing..."; \
6+
go install github.com/google/wire/cmd/wire@latest; \
7+
fi
8+
9+
@echo "Updating dependency injection";
10+
@wire di/wire.go;
11+
12+
update_mocks:
13+
@if !command -v mockery >/dev/null 2>&1 ; then \
14+
echo "Mockery is not installed. Installing..."; \
15+
go install github.com/vektra/mockery/[email protected]; \
16+
fi
17+
18+
@echo "Updating mocks";
19+
@mockery;

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Chat API
2+
3+
This is a web chat API that allows users to create and manage chat rooms and send messages. The chat system also includes another API called Broadcaster, where users can subscribe to receive messages from a given chat room. The messages are sent from this API to Broadcaster through RabbitMQ.
4+
5+
6+
## Endpoints
7+
8+
| Endpoint | Method | Protected | Description |
9+
|------------------------------| ------ |-----------|---------------------|
10+
| `/api/v1/rooms` | POST | YES | Create a room |
11+
| `/api/v1/rooms` | GET | YES | Search rooms |
12+
| `/api/v1/rooms/{id}` | GET | YES | Find a room by id |
13+
| `/api/v1/rooms/{id}` | PUT | YES | Update a room |
14+
| `/api/v1/rooms/{id}` | DELETE | YES | Delete a room |
15+
| `/api/v1/rooms/{id}/send` | POST | YES | Send a message |
16+
| `/api/v1/swagger/index.html` | GET | NO | API's documentation |
17+
| `/api/v1/healthz` | GET | NO | Health check |
18+
19+
## Documentation
20+
21+
The API is running in a Kubernetes cluster using GKE on GCP. Check out the documentation on:
22+
23+
- [Chat API](https://git.chat.api.sesaque.com/api/v1/swagger/index.html)
24+
25+
Other related repositories are:
26+
27+
- [Chat App](https://github.com/sesaquecruz/react-chat-app)
28+
- [Broadcaster API](https://github.com/sesaquecruz/go-chat-broadcaster)
29+
- [Chat Infra](https://github.com/sesaquecruz/k8s-chat-infra)
30+
- [Chat API Docker Hub](https://hub.docker.com/r/sesaquecruz/go-chat-api/tags)
31+
32+
## Tech Stack
33+
34+
- [Go](https://go.dev)
35+
- [Gin](https://gin-gonic.com)
36+
- [Postgres](https://www.postgresql.org)
37+
- [RabbitMQ](https://www.rabbitmq.com)
38+
39+
40+
## Contributing
41+
42+
Contributions are welcome! If you find a bug or would like to suggest an enhancement, please make a fork, create a new branch with the bugfix or feature, and submit a pull request.
43+
44+
## License
45+
46+
This project is licensed under the MIT License. See [LICENSE](./LICENSE) file for more information.

cmd/chat/main.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/sesaquecruz/go-chat-api/config"
7+
"github.com/sesaquecruz/go-chat-api/di"
8+
"github.com/sesaquecruz/go-chat-api/pkg/log"
9+
)
10+
11+
// @title Chat API
12+
// @version 1.0.0
13+
// @description A Rest API for Chat App.
14+
// @termsOfService https://github.com/sesaquecruz/go-chat-api
15+
16+
// @contact.name API Support
17+
// @contact.url https://github.com/sesaquecruz/go-chat-api
18+
19+
// @license.name MIT
20+
// @license.url https://github.com/sesaquecruz/go-chat-api
21+
22+
// @BasePath /api/v1
23+
24+
// @securityDefinitions.apikey Bearer token
25+
// @in header
26+
// @name Authorization
27+
// @description API authorization token
28+
29+
func main() {
30+
logger := log.NewLogger("Main")
31+
32+
cfg := config.Load()
33+
34+
router := di.NewRouter(&cfg.Database, &cfg.Broker, &cfg.Api)
35+
addr := fmt.Sprintf(":%s", cfg.Api.Port)
36+
37+
logger.Infof("server started on %s\n", addr)
38+
router.Run(addr)
39+
}

config.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[app.database]
2+
host = "localhost"
3+
port = "5432"
4+
user = "postgres"
5+
password = "postgres"
6+
name = "chat"
7+
8+
[app.broker]
9+
host = "localhost"
10+
port = "5672"
11+
user = "guest"
12+
password = "guest"
13+
14+
[app.api]
15+
port = "8080"
16+
path = "/api/v1"
17+
mode = "release"
18+
19+
[app.api.cors]
20+
origins = "*"
21+
22+
[app.api.jwt]
23+
issuer = "https://dev-j6pmr0ckitt2062o.us.auth0.com/"
24+
audience = "https://dev-j6pmr0ckitt2062o.us.auth0.com/userinfo"

0 commit comments

Comments
 (0)