This is a JSON API server written in Go that provides endpoints for managing users, customers, products, sales, and expenses.
- User authentication and authorization
- CRUD operations for users, customers, products, sales, and expenses
- Integration with AWS S3 for file storage
The server uses PostgreSQL as its database backend. It provides a NewPostgresStore
function to create a new instance of PostgresStore
, which establishes a connection to the PostgreSQL database and initializes necessary extensions.
The server integrates with AWS S3 for file storage. The BucketBasics
struct encapsulates Amazon S3 actions such as uploading and deleting files. It provides methods for uploading base64-encoded images to an S3 bucket and deleting files from the bucket.
The server includes helper functions for handling JSON responses, HTTP request routing, and working with PostgreSQL array types.
└── golang-dashboard/
├── Makefile
├── api.go
├── auth.go
├── customer.service.go
├── customer.storage.go
├── customer.types.go
├── database.go
├── expense.service.go
├── expense.storage.go
├── expense.types.go
├── earnings.service.go
├── earnings.storage.go
├── earnings.types.go
├── go.mod
├── go.sum
├── main.go
├── product.service.go
├── product.storage.go
├── product.types.go
├── s3.go
├── sale.service.go
├── sale.storage.go
├── sale.types.go
├── storage.go
├── user.service.go
├── user.storage.go
├── user.types.go
└── utils.go
The server exposes the following endpoints:
POST /login
: User loginPOST /signup
: User sign up
Protected routes with JWT
GET /users
: Get all usersGET /users/{id}
: Get user by IDGET /customers
: Get all customersGET /customers/{id}
: Get customer by IDPOST /customers
: Create a new customerPUT /customers/{id}
: Update customer by IDDELETE /customers/{id}
: Delete customer by IDGET /products
: Get all productsGET /products/{id}
: Get product by IDPOST /products
: Create a new productPUT /products/{id}
: Update product by IDDELETE /products/{id}
: Delete product by IDGET /sales
: Get all salesGET /sales/{id}
: Get sale by IDPOST /sales
: Create a new saleGET /expenses
: Get all expensesGET /expenses/{id}
: Get expense by IDPOST /expenses
: Create a new expensePUT /expenses/{id}
: Update expense by IDDELETE /expenses/{id}
: Delete expense by IDGET /earnings
: Get earnings by month calculated from multiple postgres tables
This project depends on the following external packages:
- github.com/aws/aws-sdk-go-v2 - AWS SDK for Go
- github.com/golang-jwt/jwt/v5 - JWT implementation for Go
- github.com/google/uuid - UUID generation library for Go
- github.com/gorilla/mux - Powerful HTTP router and URL matcher for building Go web servers
- github.com/joho/godotenv - Go port of Ruby's dotenv library for loading environment variables from .env files
- github.com/lib/pq - PostgreSQL driver for Go's database/sql package
- golang.org/x/crypto - Supplementary cryptography libraries for Go
- github.com/sendgrid/sendgrid-go - SendGrid email service
- github.com/sendgrid/rest - SendGrid email service
Requirements
You may need to configure environment variables or configuration files for database connection, AWS credentials, and other settings.
Ensure you have the following dependencies installed on your system:
- Go:
version go1.22.2
- Clone the golang-dashboard repository:
git clone https://github.com/AndresCampuzano/golang-dashboard
- Change to the project directory:
cd golang-dashboard
- Install the dependencies:
go mod download
Use the following command to run golang-dashboard:
make run
This project requires the following environment variables to be set for proper operation:
POSTGRES_USER
: PostgreSQL usernamePOSTGRES_DB_NAME
: PostgreSQL database namePOSTGRES_PASSWORD
: PostgreSQL password
AWS_ACCESS_KEY_ID
: AWS access key ID for accessing AWS servicesAWS_SECRET_ACCESS_KEY
: AWS secret access key for accessing AWS servicesAWS_REGION
: AWS region where resources are locatedAWS_S3_BUCKET_NAME
: Name of the AWS S3 bucket for file storageAWS_S3_BUCKET_URL
: URL of the AWS S3 bucket for accessing stored files
AMAZON_RDS_USER
: Username for Amazon RDS databaseAMAZON_RDS_DB_NAME
: Name of the Amazon RDS databaseAMAZON_RDS_PASSWORD
: Password for Amazon RDS databaseAMAZON_RDS_ENDPOINT
: Endpoint for connecting to Amazon RDS database
JWT_SECRET
: Secret key for JWT token generation
SENDGRID_API_KEY
: SendGrid API KeySENDGRID_CUSTOM_SENDER
: Custom email sender
Embrace the chaos, this is a work in progress!