You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+65-35Lines changed: 65 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -40,11 +40,12 @@ This project crafts a fully functional blueprint of Golang serverless RESTful ap
40
40
41
41
[AWS CDK](https://aws.amazon.com/cdk) is amazing technology to automate the development and operation of application into one process and one codebase.
42
42
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
+
44
45
45
46
## Installation
46
47
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.
48
49
49
50
```
50
51
go get github.com/fogfish/blueprint-serverless-golang
*[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
80
83
81
84
82
85
## Getting started
83
86
84
87
**Let's have a look on the repository structure**
85
88
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:
87
90
88
91
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.
89
92
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.
91
94
92
95
3. Main packages build lambda functions and ties everything together.
93
96
94
97
```
95
98
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
+
└─ ...
118
140
```
119
141
120
142
### Development workflows
121
143
122
-
**dependencies**
144
+
**unit testing**
123
145
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
125
147
126
148
```bash
127
-
go get -d ./...
149
+
go test ./...
128
150
```
129
151
130
-
**unit testing**
152
+
**local testing**
131
153
132
-
Test the Golang application and its cloud infrastructure
154
+
Run application locally
133
155
134
156
```bash
135
-
go test ./...
157
+
go run cmd/server/main.go
158
+
assay-it test --target http://127.1:8080
136
159
```
137
160
138
161
**build**
@@ -154,9 +177,16 @@ cdk deploy
154
177
In few seconds, the application becomes available at
0 commit comments