This is a basic command line cloud ticketing system. It supports customers to create tickets, agents to respond, and an admin (initialized during setup) to oversee and manage everything. There are 3 subcommands:
- Setup: For database initialization, migration and admin user creation
- run: Starts the server
- version: Shows application version
To run the project, first clone it using the http/ssh key with
- git clone <ssh_key>
- cd cloud-ticketing
Then set up a config.yaml file in your root directory with the following format:
database:
host:
port:
user:
password:
name:
sslmode:
server:
port:
jwt:
secret:
admin:
email:
password:
Here in database field, host, port, user, password, name, sslmode should be your database credentials. In server field, port is the port number in which you want to run your server. In jwt field, secret is the secret word you want to bind with the authorization token. In admin field, email and password are the credentials you want to use for your admin account.
For running it locally, you need to install Go and PostgreSQL. Then run it using
- go run main.go setup => for setup subcommand
- go run main.go run => for run subcommand
- go run main.go version => for version subcommand
You can override the config values using flags. For example,
- go run main.go run --server.port=8080 can initiate the server at 8080 port, even if the config file contains different port number.
Otherwise for running the project using Docker,
First install Docker:
- For Windows/macOS: Install Docker Desktop from https://www.docker.com/products/docker-desktop/
- For Linux: Install Docker Engine using your package manager.
An example for Ubuntu:
Ensure Docker is installed and running:
sudo apt update sudo apt install docker.io docker-compose sudo systemctl enable docker sudo systemctl start dockerdocker --version docker compose version
Then add Docker Support: Create two new files in your projects' root directory with the same name as the following:
- touch Dockerfile
- touch docker-compose.yaml
Dockerfile:
FROM golang:1.23-alpine AS builder
WORKDIR /app
RUN apk add --no-cache git
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG VERSION=development
ARG GIT_COMMIT=unknown
ARG BUILD_DATE=undefined
RUN apk add --no-cache build-base && \
CGO_ENABLED=1 GOOS=linux go build -tags netgo -ldflags "\
-linkmode external -extldflags '-static' \
-X github.com/notTabassum/cloud-ticketing/cmd/cloud-ticketing/version.Version=${VERSION} \
-X github.com/notTabassum/cloud-ticketing/cmd/cloud-ticketing/version.GitCommit=${GIT_COMMIT} \
-X github.com/notTabassum/cloud-ticketing/cmd/cloud-ticketing/version.BuildDate=${BUILD_DATE}" \
-o cloud-ticketing ./cmd/cloud-ticketing
FROM alpine:3.20
WORKDIR /app
RUN apk add --no-cache bash
COPY --from=builder /app/cloud-ticketing .
COPY config.yaml .
CMD ["./cloud-ticketing", "run"]
docker-compose.yaml:
version: "3.8"
services:
db:
image: postgres:14
environment:
POSTGRES_USER: <user>
POSTGRES_PASSWORD: <password>
POSTGRES_DB: <database>
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
setup:
build: .
depends_on:
- db
volumes:
- ./config.yaml:/app/config.yaml
command: ["./cloud-ticketing", "setup"]
app:
build: .
depends_on:
- db
- setup
volumes:
- ./config.yaml:/app/config.yaml
ports:
- "8080:8080"
command: ["./cloud-ticketing", "run"]
version:
build: .
depends_on:
- db
volumes:
- ./config.yaml:/app/config.yaml
command: ["./cloud-ticketing", "version"]
volumes:
pgdata:
Use the same values for database user, password and database name as your config.yaml Also in your config.yaml, the database host name should match the service name mentioned in the docker-compose.yaml(here, "db"). Then you can run the project using:
- Setup: docker compose run setup
- Run: docker compose up
- Version: docker compose run version
To shut everything down:
- docker compose down -v --remove-orphans
After running the application, you can call the APIs through curl commands. Here is the documentation for all the API endpoints:
For Login(Unauthorized API call):
curl --location 'http://localhost:8080/user/login' \
--header 'Content-Type: text/plain' \
--data-raw '{
"email": "admin@appscode.com",
"password": "1234"
}'
For Registering Customer/Agent:
curl --location 'http://localhost:8080/user' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-jwt-token>'
--data-raw '{
"name": "Rahima Khatun",
"email": "rahima@example.com",
"password": "secret125",
"role": "customer"
}'
For Fetching Users:
curl --location 'http://localhost:8080/user/list' \
--header 'Authorization: Bearer <your-jwt-token>'
For fetching specific user:
curl --location 'http://localhost:8080/user/4' \
--header 'Authorization: <your-jwt-token>'
For updating user profile:
curl --location --request PUT 'http://localhost:8080/user/3' \
--header 'Content-Type: text/plain' \
--header 'Authorization: Bearer <your-jwt-token>' \
--data '{
"password": "secret124"
}'
For deleting users:
curl --location --request DELETE 'http://localhost:8080/user/5' \
--header 'Authorization: Bearer <your-jwt-token>'
For creating tickets:
curl --location 'http://localhost:8080/ticket' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-jwt-token>' \
--data '{
"title": "Net Issue",
"description": "Wifi is off from morning",
"category": "technical issue",
"priority": "urgent"
}'
For fetching tickets:
curl --location 'http://localhost:8080/ticket' \
--header 'Authorization: Bearer <your-jwt-token>'
For fetching specific ticket:
curl --location 'http://localhost:8080/ticket/specific/1' \
--header 'Authorization: Bearer <your-jwt-token>'
For updating ticket:
curl --location --request PUT 'http://localhost:8080/ticket/1' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-jwt-token>' \
--data '{
"assigned_to": 4,
"ticket_status": "in progress"
}'
For deleting tickets:
curl --location --request DELETE 'http://localhost:8080/ticket/2' \
--header 'Authorization: Bearer <your-jwt-token>'