isaka-james / go-server

Your One to Go golang server template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go Server Template

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.

Features

  • 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.

Getting Started

Prerequisites

  • Go (version 1.22+)
  • Git
  • Docker (optional, for containerization)

Installation

  1. Clone the repository:

    git clone https://github.com/isaka-james/go-server.git
    cd go-server
  2. Install dependencies:

    go mod tidy
  3. 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
  4. Run the server:

    go run main.go

    The server should now be running on http://localhost:80.

Using Docker

  1. Build the Docker image:

    docker build -t go-server-template .
  2. Run the Docker container:

    docker run -p 80:80 go-server-template

    The server should now be running on http://localhost:80.

Project Structure

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 and go.sum: Go modules files.
  • main.go: Entry point of the application.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

since 15 May,2024

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Your One to Go golang server template

License:MIT License


Languages

Language:Go 100.0%