Discover Packages
github.com/akramfirmansyah/golang-template
command
module
Version:
v0.0.0-...-cbaa2f3
Opens a new window with list of versions in this module.
Published: Jun 11, 2024
License: MIT
Opens a new window with license information.
Imports: 9
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Golang API Template
This repository serves as a template for building a RESTful API using Golang. It provides a structured layout with predefined folders and files to help you kickstart your API development.
Project Structure
.
├── main.go
├── config
├── controller
├── database
│ ├── index.go
│ ├── migration
│ └── seeder
├── middleware
├── public
├── routes
└── utils
Folder and File Descriptions
main.go : The entry point of the application.
config : Contains configuration files for the application.
controller : Contains the logic for handling requests and sending responses.
database : Contains database related files and folders.
index.go : Database connection and setup.
migration : Folder for database migration files.
seeder : Folder for database seed files.
middleware : Contains middleware functions for the application.
public : Publicly accessible files (e.g., images, CSS, JavaScript).
routes : Contains route definitions and mappings.
utils : Utility functions and helpers.
Getting Started
Prerequisites
golang installed (version 1.17 or higher recommended)
Docker installed (optional, for containerized development)
Installation
Clone the repository:
git clone
cd golang-template
Install dependencies:
go mod tidy
Set up the database:
Ensure your database is running
Copy .env.example
and save as .env
file
Congifure the database connection in the .env
file such as username , password and database name .
Migrations and seeders will be automatically when the file main.go
is run.
Run the application:
go run main.go
Docker Setup (Optional)
To run the application in a Docker container, follow these steps:
Build the Docker image:
docker build -t golang-api-template .
Run the Docker container:
docker run -p 8080:8000 golang-template
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Directories
¶
Click to show internal directories.
Click to hide internal directories.