Golang APIs Kickstart is a starter project for building APIs using Go. It includes database initialization, configuration management, and templating for web pages.
- GORM: For ORM and database management.
- SQLite: As the default database.
- HTML Templates: For rendering web pages.
- Configuration Management: Using a custom configuration loader.
.
├── README.md
├── env.sample
├── go.mod
├── go.sum
├── database.db
├── cmd
│ ├── api
│ │ └── main.go # Main entry point for the API server
│ └── migrate
│ └── migrate.go # Database migration script
├── internal
│ ├── config
│ │ └── config.go # Configuration management
│ ├── controllers
│ │ └── users.go # User-related API controllers
│ ├── database
│ │ └── db.go # Database initialization and connection
│ ├── dto
│ │ └── authInput.go # Data Transfer Objects (DTOs)
│ ├── middleware
│ │ └── checkAuth.go # Authentication middleware
│ ├── models
│ │ └── users.go # Database models
│ ├── routes
│ │ └── main.go # API route definitions
│ └── templates
│ ├── layouts
│ │ └── base.html # Base layout for HTML templates
│ ├── pages
│ │ └── index.html # Main page template
│ └── partials
│ ├── footer.html # Footer partial template
│ └── header.html # Header partial template
├── scripts
│ └── generate_html.sh # Script for HTML generation
└── tmp
├── build-errors.log # Log file for build errors
└── main # Temporary main build file
18 directories, 21 files
- Go 1.19 or later
- SQLite
-
Clone the repository:
git clone https://github.com/yourusername/golang-apis-kickstart.git cd golang-apis-kickstart
-
Install dependencies:
go mod tidy
-
Initialize the database:
go run cmd/migrate/migrate.go
-
Run the application:
go run main.go
Configuration is managed in the internal/config
package. Ensure to load the configuration at the start of your application.
The database is initialized in the internal/database
package. The Init
function sets up the SQLite database.
HTML templates are located in the internal/templates
directory. The base layout is defined in layouts/base.html
, and individual pages are in the pages
directory.
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License.