This project represents my journey in learning the Go programming language by building a simple Content Management System (CMS) API. My goal was to understand Go's core concepts, web development patterns, and best practices by applying them in a real-world project.
- Go 1.23.3 or later
- PostgreSQL database
- Vercel account (for deployment)
-
Clone the repository:
git clone <repository-url> cd cms-project
-
Install dependencies:
go mod download
-
Set up environment variables:
- Create a
.envfile in the root directory. - Add the following variables:
DATABASE_URL=postgres://username:password@localhost:5432/dbname PORT=8080
- Create a
-
Run the project locally:
go run main.go
-
Access the API documentation at
http://localhost:8080/swagger/index.html.
- Deploy the project on Vercel using the provided
vercel.jsonconfiguration.
- Go Basics: Syntax, data types, functions, error handling, and package management.
- Project Structure: Organizing code using Go modules, packages, and a clean directory structure (
internal/,router/, etc.). - Web Development:
- Using the Gorilla Mux router for HTTP routing and middleware.
- Implementing RESTful API endpoints for users and navigation links.
- Handling CORS and HTTP methods.
- Database Integration:
- API Documentation:
- Generating and serving Swagger documentation with swaggo and http-swagger.
- Deployment:
- Preparing the project for deployment on Vercel using
vercel.json.
- Preparing the project for deployment on Vercel using
main.go: Entry point, server setup, and initialization.internal/: Business logic, database, and feature modules (users, navLinks).router/: HTTP routing and middleware.docs/: Auto-generated Swagger documentation.
- Modular Design: The project is structured into modules (
internal/,router/, etc.) to promote separation of concerns and maintainability. - Use of Gorilla Mux: Chosen for its flexibility and ease of use in handling HTTP routing and middleware.
- Database Abstraction: Using
sqlxfor database operations to simplify SQL queries and improve code readability. - Environment Configuration: Utilizing
godotenvfor managing environment variables, ensuring secure and flexible configuration. - API Documentation: Implementing Swagger for auto-generating API documentation, making it easier for developers to understand and use the API.
- Deployment Strategy: Using Vercel for deployment, leveraging its serverless architecture for scalability and ease of use.
- Go's simplicity and performance make it ideal for backend APIs.
- Strong typing and clear error handling improve code reliability.
- The Go ecosystem provides robust libraries for web, database, and documentation needs.
- Structuring a Go project with clear separation of concerns is crucial for maintainability.
- Add authentication and authorization.
- Expand API features (e.g., more CMS entities).
- Write unit and integration tests.
- Explore Go's concurrency features for performance improvements.
This project is a work in progress and a reflection of my ongoing learning in Go. Feedback and suggestions are welcome!