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.