A modern Go API service that integrates with Supabase for authentication and database operations.
- RESTful API using Gin framework
- JWT-based authentication
- Supabase integration for database and auth
- Structured project layout following Go best practices
- Middleware for logging, authentication, and authorization
- Graceful server shutdown
- Configuration management
- Error handling
├── cmd/
│ └── api/ # Application entrypoints
│ └── main.go # Main application
├── config/ # Configuration handling
│ └── config.go
├── internal/ # Private application code
│ ├── handlers/ # HTTP handlers
│ ├── middleware/ # HTTP middleware
│ ├── models/ # Data models
│ ├── repository/ # Database repositories
│ └── services/ # Business logic
├── pkg/ # Public libraries
│ ├── database/ # Database client
│ ├── logger/ # Logging utilities
│ └── utils/ # Utility functions
├── .env # Environment variables
├── go.mod # Go module file
├── go.sum # Go module checksum
└── README.md # Project documentation
- Go 1.22 or higher
- Supabase account and project
-
Clone the repository:
git clone https://github.com/peterlimg/supabase-e.git cd supabase-e -
Set up your Supabase project:
- Create a new Supabase project
- Create the necessary tables (users, products)
- Get your Supabase URL and API keys
-
Configure environment variables:
- Copy
.env.exampleto.env - Update the values with your Supabase credentials
- Copy
-
Install dependencies:
go mod download -
Run the application:
go run cmd/api/main.go
POST /api/v1/auth/register- Register a new userPOST /api/v1/auth/login- Login and get JWT token
GET /api/v1/users/me- Get current user profilePUT /api/v1/users/me- Update current user profile
GET /api/v1/products- List all productsPOST /api/v1/products- Create a new productGET /api/v1/products/:id- Get a product by IDGET /api/v1/products/:id/with-user- Get a product with creator infoPUT /api/v1/products/:id- Update a productDELETE /api/v1/products/:id- Delete a product
GET /health- Check API health
CREATE TABLE users (
id UUID PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
role TEXT NOT NULL DEFAULT 'user',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);CREATE TABLE products (
id UUID PRIMARY KEY,
name TEXT NOT NULL,
description TEXT NOT NULL,
price DECIMAL NOT NULL,
category TEXT NOT NULL,
image_url TEXT,
created_by UUID REFERENCES users(id),
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);MIT