Skip to content

hotspoon/go-northwind-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Northwind API

A RESTful API for the classic Northwind database, built with Go and Gin. This project demonstrates clean architecture, modular design, JWT authentication, and structured logging using zerolog.

Features

  • Customer and Employee endpoints (CRUD)
  • JWT-based authentication (middleware)
  • Swagger/OpenAPI documentation (docs/swagger.yaml)
  • Structured logging to app.log
  • Environment-based configuration
  • Graceful shutdown
  • SQLite database (northwind.db)

Project Structure

.
├── main.go
├── go.mod
├── internal/
│   ├── config/         # App config & DB setup
│   ├── handlers/       # HTTP handlers
│   ├── logging/        # Logger setup & middleware
│   ├── middleware/     # Custom Gin middleware
│   ├── models/         # Data models & responses
│   ├── repositories/   # Data access layer
│   ├── routes/         # Route registration
│   ├── server/         # Gin engine setup
│   └── utils/          # Utilities (e.g., JWT)
├── docs/               # Swagger docs
├── northwind.db        # SQLite database
├── .env                # Environment variables
├── .air.toml           # Live reload config
└── tmp/                # Build artifacts

Getting Started

Prerequisites

  • Go 1.18+
  • swag (for Swagger docs)
  • SQLite3

Setup

  1. Clone the repo:

    git clone https://github.com/yourusername/northwind-api.git
    cd northwind-api
  2. Copy and edit .env:

    cp .env.example .env
    # Edit as needed (JWT_SECRET, PORT, etc.)
  3. Install dependencies:

    go mod tidy
  4. Generate Swagger docs:

    swag init -g main.go -o ./docs
  5. Run the server:

    go run main.go
    # or with live reload (requires air)
    air

API Documentation

Configuration

See internal/config/config.go for config loading. Main environment variables:

  • JWT_SECRET (required)
  • PORT (default: 8080)
  • DB_PATH (default: northwind.db)
  • GO_ENV (default: development)
  • API_VERSION (default: v1)

Logging

License

MIT


See also:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages