This project is a Go implementation of an auction site API that supports different types of auctions:
- Timed Ascending (English) auctions - where bidders openly bid against each other, and the highest bidder wins
- Single Sealed Bid auctions:
- Blind - highest bidder pays their bid amount
- Vickrey - highest bidder pays the second-highest bid amount
- RESTful API for creating auctions and placing bids
- Support for different auction types
- Persistence using JSON files
- JWT-based authentication
- Domain-driven design with clean separation of concerns
- Go 1.18 or newer
- Clone the repository
git clone https://github.com/wallymathieu/auction-site-go.git
cd auction-site-go
- Install dependencies
go mod download
- Build the application
go build -o auction-site ./cmd/server
./auction-site
The server will start on port 8080.
All write operations require authentication via the x-jwt-payload
header. Note that the x-jwt-payload
header is a decoded JWT and not an actual JWT, since this app is supposed to be deployed behind a front-proxy.
Example JWT payload format for a buyer/seller:
{
"sub": "a1",
"name": "Test User",
"u_typ": "0"
}
Example JWT payload format for support:
{
"sub": "s1",
"u_typ": "1"
}
The JWT payload should be Base64 encoded when sent in the header.
GET /auctions
- List all auctionsGET /auction/:id
- Get auction details, including bids and winner information if availablePOST /auction
- Create a new auctionPOST /auction/:id/bid
- Place a bid on an auction
curl -X POST http://localhost:8080/auction \
-H "Content-Type: application/json" \
-H "x-jwt-payload: eyJzdWIiOiJhMSIsICJuYW1lIjoiVGVzdCIsICJ1X3R5cCI6IjAifQo=" \
-d '{
"id": 1,
"startsAt": "2023-01-01T10:00:00.000Z",
"endsAt": "2023-12-31T10:00:00.000Z",
"title": "Test Auction",
"currency": "VAC"
}'
curl -X POST http://localhost:8080/auction/1/bid \
-H "Content-Type: application/json" \
-H "x-jwt-payload: eyJzdWIiOiJhMiIsICJuYW1lIjoiQnV5ZXIiLCAidV90eXAiOiIwIn0K=" \
-d '{
"amount": 100
}'
Auction
- Represents an auction with ID, title, start/end times, seller, type, and currencyBid
- Represents a bid on an auction with auction ID, bidder, time, and amountState
- Interface for different auction state implementationsCommand
- Interface for commands that can be executed against the systemEvent
- Interface for events generated as a result of commands
Each auction type implements a state machine:
AwaitingStartState
- Auction hasn't started yetOngoingState
- Auction is active and accepting bidsEndedState
- Auction has ended
SealedBidState
- Accepts bids until the expiry time- After expiry, bids are disclosed and the winner is determined
Run the tests with:
go test ./...
The codebase follows a clean architecture with the following layers:
- Domain - Core business logic and types
- Persistence - Data storage
- Web - HTTP API and request handling
auction-site-go/
├── cmd/
│ └── server/ # Entry point for the application
├── internal/
│ ├── domain/ # Domain models and business logic
│ ├── persistence/ # Data storage
│ └── web/ # HTTP API
└── tests/ # Integration tests
This project is licensed under the MIT License - see the LICENSE file for details.