Skip to content

Commit 6d15f63

Browse files
committed
refactor project layout
1 parent 77d7ec5 commit 6d15f63

File tree

19 files changed

+125
-83
lines changed

19 files changed

+125
-83
lines changed

.assay-it.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"suites": [
3-
"suites/petshop.go"
3+
"http/suites/petshop.go"
44
]
55
}

.github/workflows/build.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ jobs:
1818

1919
- uses: actions/checkout@v2
2020

21-
- uses: fogfish/deploy-cdk-go@latest
21+
- id: deploy
22+
uses: fogfish/deploy-cdk-go@latest
2223
with:
23-
go-version: 1.18
24+
go-version: "1.20"
2425
stack: ${{ matrix.stack }}
2526
version: latest
2627
issue-to-create: ./.github/issue-spawn-latest.md
2728
aws-access-key: ${{ secrets.AWS_ACCESS_KEY }}
2829
aws-secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
2930
aws-region: eu-west-1
31+
32+
- uses: assay-it/github-actions-quality-check@latest
33+
with:
34+
install-go: false
35+
system-under-test: ${{ steps.deploy.outputs.deployed-api }}

.github/workflows/carry.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ jobs:
1515

1616
- uses: actions/checkout@v2
1717

18-
- uses: fogfish/deploy-cdk-go@latest
18+
- id: deploy
19+
uses: fogfish/deploy-cdk-go@latest
1920
with:
20-
go-version: 1.18
21+
go-version: "1.20"
2122
stack: ${{ matrix.stack }}
2223
version: ${{ github.event.release.name }}
2324
issue-to-create: ./.github/issue-spawn-release.md
2425
aws-access-key: ${{ secrets.AWS_ACCESS_KEY }}
2526
aws-secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
2627
aws-region: eu-west-1
28+
29+
- uses: assay-it/github-actions-quality-check@latest
30+
with:
31+
install-go: false
32+
system-under-test: ${{ steps.deploy.outputs.deployed-api }}

.github/workflows/check-clean.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
- uses: fogfish/deploy-cdk-go@latest
2323
with:
24-
go-version: 1.18
24+
go-version: "1.20"
2525
command: destroy
2626
stack: ${{ matrix.stack }}
2727
version: pr${{ github.event.number }}

.github/workflows/check-code.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
- uses: actions/setup-go@v3
2020
with:
21-
go-version: 1.18
21+
go-version: "1.20"
2222
cache: true
2323

2424
- uses: dominikh/[email protected]

.github/workflows/check-spawn.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ jobs:
2222

2323
- id: deploy
2424
uses: fogfish/deploy-cdk-go@latest
25-
env:
26-
CGO_ENABLED: 0
2725
with:
2826
go-version: "1.20"
2927
stack: ${{ matrix.stack }}

.github/workflows/check-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
- uses: actions/setup-go@v3
2525
with:
26-
go-version: 1.18
26+
go-version: "1.20"
2727
cache: true
2828

2929
- name: go build

README.md

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ This project crafts a fully functional blueprint of Golang serverless RESTful ap
4040

4141
[AWS CDK](https://aws.amazon.com/cdk) is amazing technology to automate the development and operation of application into one process and one codebase.
4242

43-
However, seeding of new repository for development of Golang serverless application requires a boilerplate code. This blueprint helps you to focus on the application development than waste a time with establish project layout, configure AWS CDK, setting up CI/CD and figuring out how to testing the application. All these issues are resolved within this blueprint.
43+
However, seeding of new repository for development of Golang serverless application requires a boilerplate code. This blueprint helps you to focus on the application development than waste a time with establish **project layout**, **configure AWS CDK**, **setting up CI/CD** and figuring out how to **testing the application**. All these issues are resolved within this blueprint.
44+
4445

4546
## Installation
4647

47-
The blueprint is fully functional application that delivers a skeleton for Golang serverless development with AWS CDK. Clone the repository and follow [Getting started](#getting-started) instructions to evaluate its applicability for your purposes. It should take less than 5 minutes to build and deploy the template in AWS.
48+
The blueprint is fully functional application (Pet Store) that delivers a skeleton for Golang serverless development with AWS CDK. Clone the repository and follow [Getting started](#getting-started) instructions to evaluate its applicability for your purposes. It should take less than 5 minutes to build and deploy this blueprint to AWS.
4849

4950
```
5051
go get github.com/fogfish/blueprint-serverless-golang
@@ -75,64 +76,86 @@ git merge blueprint/main --allow-unrelated-histories --squash
7576
Before Getting started, you have to ensure
7677

7778
* [Golang](https://golang.org/dl/) development environment v1.16 or later
78-
* [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/work-with.html#work-with-prerequisites)
79-
* Access to AWS Account
79+
* [assay-it](https://assay.it) utility for testing cloud apps in production
80+
* [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/work-with.html#work-with-prerequisites) for deployment of serverless application using infrastructure as a code
81+
* [GitHub](https://github.com) account for managing source code and running CI/CD pipelines as [GitHub Actions](https://docs.github.com/en/actions)
82+
* Account on [Amazon Web Services](https://aws.amazon.com) for running the application in production
8083

8184

8285
## Getting started
8386

8487
**Let's have a look on the repository structure**
8588

86-
The structure resembles the standard package layout proposed in [this blog post](https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1):
89+
The structure resembles the mixture of [Standard package layout](https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1) and [Hexagonal architecture](https://medium.com/@matiasvarela/hexagonal-architecture-in-go-cfd4e436faa3). The proposed structure is better version of Hexagonal architecture that follows Golang best practices:
8790

8891
1. the root package contains core types to describe domain of your application. It contains simple types that has no dependency to technology but their implements core logic and use-cases.
8992

90-
2. Use sub-packages to isolate dependencies to external technologies so that they act as bridge between your domain and technology adaptation.
93+
2. Use sub-packages to isolate dependencies to external technologies so that they act as bridge between your domain and technology adaptation.
9194

9295
3. Main packages build lambda functions and ties everything together.
9396

9497
```
9598
github.com/.../the-beautiful-app
96-
├─ stub.go // domain types, unit test
97-
├─ ... // "algebra" of your application
98-
|
99-
├─ http // RESTful API and HTTP protocol
100-
| ├─ api.go // api endpoint(s), unit tests,
101-
| └─ ... // other endpoints
102-
|
103-
├─ cmd // executables of the project
104-
| └─ lambda // aws lambda's are main packages
105-
| ├─ scud // each lambda stays at own executable
106-
| | └─ main.go
107-
| └─ ...
108-
|
109-
├─ cloud // IaC, aws cdk application
110-
| └─ ... // orchestrate ops model
111-
|
112-
├─ .github // CI/CD with GitHub Actions
113-
| └─ ...
114-
|
115-
└─ suite // API testing suite
116-
├─ api.go // (disabled in this release)
117-
└─ ...
99+
├─ pet.go // the root defines domain types, unit test
100+
├─ ... // "algebra" of your application
101+
|
102+
├─ storage.go // defines capability requires to store core
103+
| // objects at the external storage, hex-arch
104+
| // use "port" concept to depict it
105+
|
106+
├─ internal/storage // sub-package for dependency/technology ...
107+
| // it follows the standard package layout to
108+
| // adapt domain/implementation/dependency.
109+
| // in this example storage implements in-memory
110+
| // database for all domain objects.
111+
|
112+
├─ internal/services // entry point to the core, implement app logic
113+
| └─ pets // entire logic about pets domain
114+
| ├─ fetcher.go // fetch and enrich pets objects
115+
| └─ creator.go // create pets objects
116+
|
117+
├─ internal/mock // shared mock
118+
|
119+
├─ http // public REST API exposed by application.
120+
| ├─ petshop.go // collection of petshop endpoints impl. by app
121+
| | // endpoints consumer services using ports
122+
| |
123+
| ├─ api // public objects used by API
124+
| | └─ pet.go
125+
| └─ suites // testing suites for api endpoint(s)
126+
|
127+
├─ cmd // executables of the project
128+
| ├─ lambda // aws lambda's are main packages
129+
| | ├─ petshop // each lambda stays at own executable
130+
| | | └─ main.go // single lambda pattern is not recommended
131+
| | ...
132+
| └─ server // run application as standalone server
133+
| └─ main.go
134+
|
135+
├─ cloud // IaC, aws cdk application
136+
| └─ ... // orchestrate ops model
137+
|
138+
└─ .github // CI/CD with GitHub Actions
139+
└─ ...
118140
```
119141

120142
### Development workflows
121143

122-
**dependencies**
144+
**unit testing**
123145

124-
The application requires 3rd party libraries for dev and opts. Fetch them with the following commands:
146+
Test the Golang application and its cloud infrastructure
125147

126148
```bash
127-
go get -d ./...
149+
go test ./...
128150
```
129151

130-
**unit testing**
152+
**local testing**
131153

132-
Test the Golang application and its cloud infrastructure
154+
Run application locally
133155

134156
```bash
135-
go test ./...
157+
go run cmd/server/main.go
158+
assay-it test --target http://127.1:8080
136159
```
137160

138161
**build**
@@ -154,9 +177,16 @@ cdk deploy
154177
In few seconds, the application becomes available at
155178

156179
```
157-
curl https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/api/scud
180+
curl https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/api
181+
```
182+
183+
**test in production**
184+
185+
```bash
186+
assay-it test --target https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/api
158187
```
159188

189+
160190
**destroy**
161191

162192
Destroy the application and remove all its resource from AWS account

cmd/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package cmd
33
import (
44
core "github.com/fogfish/blueprint-serverless-golang"
55
"github.com/fogfish/blueprint-serverless-golang/http"
6-
"github.com/fogfish/blueprint-serverless-golang/internal/cache"
76
"github.com/fogfish/blueprint-serverless-golang/internal/mock"
87
"github.com/fogfish/blueprint-serverless-golang/internal/services/pets"
8+
cache "github.com/fogfish/blueprint-serverless-golang/internal/storage"
99
)
1010

1111
func NewPetShopAPI() *http.PetShopAPI {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ require (
88
github.com/aws/aws-lambda-go v1.38.0
99
github.com/aws/constructs-go/constructs/v10 v10.1.270
1010
github.com/aws/jsii-runtime-go v1.77.0
11-
github.com/fogfish/it v1.0.0
11+
github.com/fogfish/it v1.0.0 // indirect
1212
github.com/fogfish/scud v0.6.0
1313
)
1414

1515
require (
1616
github.com/fogfish/faults v0.2.0
1717
github.com/fogfish/gouldian/v2 v2.0.1
1818
github.com/fogfish/guid/v2 v2.0.2
19-
github.com/fogfish/gurl/v2 v2.4.0
19+
github.com/fogfish/gurl/v2 v2.5.0
2020
github.com/fogfish/it/v2 v2.0.1
2121
github.com/fogfish/schemaorg v1.14.1
2222
github.com/fogfish/skiplist v0.9.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ github.com/fogfish/gouldian/v2 v2.0.1 h1:7rAtSjv/31SRf+dROiTFmsF9UmQysSega54BFq5
2525
github.com/fogfish/gouldian/v2 v2.0.1/go.mod h1:m5lLg+DvIFucQ7rzFAWsZ5ZtIuSmnCNBoP3HY+Pncds=
2626
github.com/fogfish/guid/v2 v2.0.2 h1:apsRAnSTkft8izOvLipUstHtWYDmVum7kcunYTR5Kv8=
2727
github.com/fogfish/guid/v2 v2.0.2/go.mod h1:KkZ5T4EE3BqWQJFZBPLSHV/tBe23Xq4KvuPfwtNtepU=
28-
github.com/fogfish/gurl/v2 v2.4.0 h1:5ZJbf4HCB9QWCcPEKQ92HCSJG9SiCDfH20imm7p0r20=
29-
github.com/fogfish/gurl/v2 v2.4.0/go.mod h1:MMSAHe+Vo+EhJZ6iH1CYeKw64T11G/NAUPK0cZ2RyS4=
28+
github.com/fogfish/gurl/v2 v2.5.0 h1:S60X6w7mpPkiGL2kbBUgEh7U2o75hfKt5Bv3YnQxgtM=
29+
github.com/fogfish/gurl/v2 v2.5.0/go.mod h1:MMSAHe+Vo+EhJZ6iH1CYeKw64T11G/NAUPK0cZ2RyS4=
3030
github.com/fogfish/it v0.9.1/go.mod h1:NQJG4Ygvek85y7zGj0Gny8+6ygAnHjfBORhI7TdQhp4=
3131
github.com/fogfish/it v1.0.0 h1:kiwFHZcrkRLUydZoIoY0gTuMfj38trwvLo0YRyIkeG8=
3232
github.com/fogfish/it v1.0.0/go.mod h1:NQJG4Ygvek85y7zGj0Gny8+6ygAnHjfBORhI7TdQhp4=

http/suites/assay-it/runner.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"github.com/fogfish/gurl/v2/http"
6+
suites "github.com/fogfish/blueprint-serverless-golang/http/suites"
7+
)
8+
9+
func main() {
10+
http.WriteOnce(os.Stdout, http.New(http.WithMemento(), http.WithDefaultHost(os.Args[1])), suites.TestPetShopList, suites.TestPetShopListWithCursor, suites.TestPetShopLookup, suites.TestPetShopCreate, suites.TestPetShopCreateUnauthorized)
11+
}
File renamed without changes.
File renamed without changes.

pet.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type Category = string
66

77
type Price = float64
88

9+
// Pet is an example domain type
910
type Pet struct {
1011
ID Identity
1112
Category Category

pet_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package core_test
2+
3+
import (
4+
"testing"
5+
6+
core "github.com/fogfish/blueprint-serverless-golang"
7+
"github.com/fogfish/it/v2"
8+
)
9+
10+
func TestPet(t *testing.T) {
11+
var p core.Pet
12+
13+
it.Then(t).Should(
14+
it.Equal(p.ID, ""),
15+
it.Equal(p.Category, ""),
16+
it.Equal(p.Price, 0.0),
17+
)
18+
}

storage.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ package core
22

33
import "context"
44

5+
//
6+
// Example definition of data access objects.
7+
// Interfaces abstracts capabilities of the storage layer(s).
8+
//
9+
510
type Getter[K, V any] interface {
611
Get(context.Context, K) (V, error)
712
}

stub.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

stub_test.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)