Welcome to the Go Server Template repository! 🎉
This repository serves as a template for creating a new Golang server. It is designed to save you time and effort by providing a solid starting point so that you don't have to write your Golang server from scratch every time.
- Structured Project Layout: A well-organized project structure that follows best practices.
- Router Setup: Pre-configured routing using popular routing libraries.
- Middleware: Basic middleware included for logging, authentication, etc.
- Configuration Management: Easy configuration management using environment variables.
- Error Handling: Standardized error handling across the application.
- Database Integration: Boilerplate code for PostgreSQL integration.
- Testing: Example unit and integration tests to get you started.
- Docker Support: Dockerfile included for containerized deployments.
-
Clone the repository:
git clone https://github.com/isaka-james/go-server.git cd go-server
-
Install dependencies:
go mod tidy
-
Set up environment variables:
Edit the
.env
file in the root directory with your configurations:# THESE ARE POSTGRES CONFIG SERVERNAME_DB=localhost USERNAME_DB=admin PASSWORD_DB=group7 DATABASE=mydb PORT_DB=5432 PORT_SERVER=80
-
Run the server:
go run main.go
The server should now be running on
http://localhost:80
.
-
Build the Docker image:
docker build -t go-server-template .
-
Run the Docker container:
docker run -p 80:80 go-server-template
The server should now be running on
http://localhost:80
.
go-server/
├── README.md
├── api
│ ├── config
│ │ └── config.go
│ ├── handlers
│ │ ├── login_handler.go
│ │ └── notification_handler.go
│ ├── models
│ │ ├── credentials.go
│ │ ├── post.go
│ │ ├── responses.go
│ │ └── user.go
│ ├── routes.go
│ ├── scripts
│ │ └── mydb.sql
│ └── utils
│ └── database.go
├── go.mod
├── go.sum
└── main.go
api/
: Main directory for API-related code.config/
: Configuration management.handlers/
: Request handlers.models/
: Database models.scripts/
: SQL scripts.utils/
: Utility functions.
go.mod
andgo.sum
: Go modules files.main.go
: Entry point of the application.
Contributions are welcome! Feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.