-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sqlite database, graceful shutdown, http server, readme file
- Loading branch information
Showing
14 changed files
with
172 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SERVICE_ADDR=:3000 | ||
SQLITE_DB_FILE=sqlite.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/.* | ||
!/.env | ||
!/.gitignore | ||
/*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Clean architecture example | ||
|
||
Simple service for orders management using сlean architecture principles. | ||
|
||
Sqlite database is used as storage. | ||
|
||
Default service configuration is loaded from `.env` file, but you can override any parameters from ENV. | ||
|
||
## How to run | ||
|
||
1) Run db migrations: | ||
``` | ||
$ go install -tags 'sqlite3 sqlite' github.com/golang-migrate/migrate/v4/cmd/migrate@latest | ||
$ migrate -database "sqlite3://sqlite.db" -path db/migrations up | ||
``` | ||
|
||
2) Start service (on port 3000 by default): | ||
``` | ||
$ go run cmd/main.go | ||
``` | ||
|
||
## How to use | ||
``` | ||
$ curl --location 'localhost:3000/sale-order' \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{"customer_id": 1, "products": [{"product_id":1, "quantity": 1}]}' | ||
$ curl --location --request GET 'localhost:3000/sale-order?id=1' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS sale_order; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE IF NOT EXISTS sale_order | ||
( | ||
id INTEGER PRIMARY KEY, | ||
number TEXT UNIQUE NOT NULL, | ||
date TIMESTAMP WITH TIME ZONE NOT NULL, | ||
status INTEGER NOT NULL DEFAULT 0 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
module github.com/kiaplayer/clean-architecture-example | ||
|
||
go 1.21 | ||
go 1.22 | ||
|
||
require ( | ||
github.com/DATA-DOG/go-sqlmock v1.5.1 | ||
github.com/golang/mock v1.6.0 | ||
github.com/joho/godotenv v1.5.1 | ||
github.com/mattn/go-sqlite3 v1.14.22 | ||
github.com/stretchr/testify v1.8.4 | ||
) | ||
|
||
require ( | ||
github.com/DATA-DOG/go-sqlmock v1.5.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/golang/mock v1.6.0 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/stretchr/testify v1.8.4 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.