Skip to content

Commit

Permalink
update blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
fogfish committed Mar 15, 2024
1 parent 3df2387 commit f49eaf9
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ node_modules/
.vscode/

assay-it/

cdk.context.json
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ github.com/.../the-beautiful-app
| |
| ├─ api // public objects used by API
| | └─ pet.go
| ├─ curl // client library
| | └─ petshop.go
| └─ suites // testing suites for api endpoint(s)
|
├─ cmd // executables of the project
Expand Down Expand Up @@ -176,10 +178,24 @@ cdk deploy

In few seconds, the application becomes available at

```
```bash
curl https://xxxxxxxxxx.execute-api.eu-west-1.amazonaws.com/api
```

The api is protected by AWS IAM, request has to be signed.
Either use example client `cmd/petshop-cli` or curl directly

```bash
curl $BLUEPRINT/petshop/pets \
-XGET \
-H "Accept: application/json" \
--aws-sigv4 "aws:amz:eu-west-1:execute-api" \
--user "$AWS_ACCESS_KEY_ID":"$AWS_SECRET_ACCESS_KEY"
```

See [all available endpoints](./http/petshop.go).


**test in production**

```bash
Expand Down
18 changes: 11 additions & 7 deletions cloud/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"

"github.com/aws/aws-cdk-go/awscdk/v2"
"github.com/aws/aws-cdk-go/awscdk/v2/awsapigateway"
"github.com/aws/aws-cdk-go/awscdk/v2/awsapigatewayv2"
"github.com/aws/constructs-go/constructs/v10"
"github.com/aws/jsii-runtime-go"
"github.com/fogfish/scud"
Expand Down Expand Up @@ -35,8 +35,11 @@ func main() {
//
// Stack
//
stackID := fmt.Sprintf("blueprint-golang-%s", vsn(app))
stack := awscdk.NewStack(app, jsii.String(stackID), config)
vsn := vsn(app)
stack := awscdk.NewStack(app,
jsii.String(fmt.Sprintf("blueprint-golang-%s", vsn)),
config,
)

NewBlueprint(stack)

Expand All @@ -46,16 +49,17 @@ func main() {
// NewBlueprint create example REST api
func NewBlueprint(scope constructs.Construct) {
gateway := scud.NewGateway(scope, jsii.String("Gateway"),
&awsapigateway.RestApiProps{
RestApiName: jsii.String("petshop"),
&scud.GatewayProps{
HttpApiProps: &awsapigatewayv2.HttpApiProps{},
},
)
gateway.WithAuthorizerIAM()

myfun := scud.NewFunctionGo(scope, jsii.String("MyFun"),
handler := scud.NewFunctionGo(scope, jsii.String("Handler"),
&scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/blueprint-serverless-golang",
SourceCodeLambda: "cmd/lambda/petshop",
},
)
gateway.AddResource("petshop", myfun)
gateway.AddResource("/petshop", handler)
}
56 changes: 56 additions & 0 deletions cmd/petshop-cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/fogfish/blueprint-serverless-golang/http/curl"
"github.com/fogfish/gurl/awsapi"
"github.com/fogfish/gurl/v2/http"
)

// go run main.go https://XXXXXXXXXX.execute-api.eu-west-1.amazonaws.com
func main() {
fmt.Println(os.Args)

cfg, err := config.LoadDefaultConfig(context.Background())
if err != nil {
panic(err)
}

curl := curl.NewPetShop(
http.New(awsapi.WithSignatureV4(cfg)),
os.Args[1],
)

pets, err := curl.List(context.Background())
if err != nil {
panic(err)
}
output(pets)

if pets.Next != nil {
pets, err = curl.Continue(context.Background(), *pets.Next)
if err != nil {
panic(err)
}
output(pets)
}

if len(pets.Pets) > 0 {
pet, err := curl.Pet(context.Background(), pets.Pets[0].Url)
if err != nil {
panic(err)
}
output(pet)
}
}

func output(x any) {
b, _ := json.MarshalIndent(x, "|", " ")
os.Stdout.Write(b)
os.Stdout.Write([]byte("\n\n"))
}
24 changes: 20 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
module github.com/fogfish/blueprint-serverless-golang

go 1.20
go 1.21.0

toolchain go1.22.0

require (
github.com/ajg/form v1.5.2-0.20200323032839-9aeb3cf462e1 // indirect
github.com/aws/aws-cdk-go/awscdk/v2 v2.132.0
github.com/aws/aws-cdk-go/awscdk/v2 v2.133.0
github.com/aws/aws-lambda-go v1.46.0
github.com/aws/constructs-go/constructs/v10 v10.3.0
github.com/aws/jsii-runtime-go v1.95.0
github.com/fogfish/scud v0.6.0
github.com/fogfish/scud v0.7.1
)

require (
github.com/aws/aws-sdk-go-v2/config v1.27.7
github.com/fogfish/faults v0.2.0
github.com/fogfish/gouldian/v2 v2.0.5
github.com/fogfish/guid/v2 v2.0.4
github.com/fogfish/gurl/v2 v2.8.2
github.com/fogfish/gurl/awsapi v0.0.1
github.com/fogfish/gurl/v2 v2.8.3
github.com/fogfish/it/v2 v2.0.1
github.com/fogfish/schemaorg v1.22.0
github.com/fogfish/skiplist v0.15.0
Expand All @@ -24,6 +28,18 @@ require (

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.25.3 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.7 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.4 // indirect
github.com/aws/smithy-go v1.20.1 // indirect
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.202 // indirect
github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.2 // indirect
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.0.1 // indirect
Expand Down
46 changes: 40 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,48 @@ github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/ajg/form v1.5.2-0.20200323032839-9aeb3cf462e1 h1:8Qzi+0Uch1VJvdrOhJ8U8FqoPLbUdETPgMqGJ6DSMSQ=
github.com/ajg/form v1.5.2-0.20200323032839-9aeb3cf462e1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/aws/aws-cdk-go/awscdk/v2 v2.132.0 h1:eKGjvml5VBFv7EAQHOPBf3KcfkssT5DUiYw0//BotOM=
github.com/aws/aws-cdk-go/awscdk/v2 v2.132.0/go.mod h1:TpmJwOnoajvRtwnLlJoxEoppb9sVoCLfPGLdgoTDH7o=
github.com/aws/aws-cdk-go/awscdk/v2 v2.133.0 h1:BTfWR3UgFuX1YScPHOTdXm+y3we7Vk4ORANPaFWIqOE=
github.com/aws/aws-cdk-go/awscdk/v2 v2.133.0/go.mod h1:TpmJwOnoajvRtwnLlJoxEoppb9sVoCLfPGLdgoTDH7o=
github.com/aws/aws-lambda-go v1.46.0 h1:UWVnvh2h2gecOlFhHQfIPQcD8pL/f7pVCutmFl+oXU8=
github.com/aws/aws-lambda-go v1.46.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A=
github.com/aws/aws-sdk-go-v2 v1.25.3 h1:xYiLpZTQs1mzvz5PaI6uR0Wh57ippuEthxS4iK5v0n0=
github.com/aws/aws-sdk-go-v2 v1.25.3/go.mod h1:35hUlJVYd+M++iLI3ALmVwMOyRYMmRqUXpTtRGW+K9I=
github.com/aws/aws-sdk-go-v2/config v1.27.7 h1:JSfb5nOQF01iOgxFI5OIKWwDiEXWTyTgg1Mm1mHi0A4=
github.com/aws/aws-sdk-go-v2/config v1.27.7/go.mod h1:PH0/cNpoMO+B04qET699o5W92Ca79fVtbUnvMIZro4I=
github.com/aws/aws-sdk-go-v2/credentials v1.17.7 h1:WJd+ubWKoBeRh7A5iNMnxEOs982SyVKOJD+K8HIezu4=
github.com/aws/aws-sdk-go-v2/credentials v1.17.7/go.mod h1:UQi7LMR0Vhvs+44w5ec8Q+VS+cd10cjwgHwiVkE0YGU=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.3 h1:p+y7FvkK2dxS+FEwRIDHDe//ZX+jDhP8HHE50ppj4iI=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.3/go.mod h1:/fYB+FZbDlwlAiynK9KDXlzZl3ANI9JkD0Uhz5FjNT4=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.3 h1:ifbIbHZyGl1alsAhPIYsHOg5MuApgqOvVeI8wIugXfs=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.3/go.mod h1:oQZXg3c6SNeY6OZrDY+xHcF4VGIEoNotX2B4PrDeoJI=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.3 h1:Qvodo9gHG9F3E8SfYOspPeBt0bjSbsevK8WhRAUHcoY=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.3/go.mod h1:vCKrdLXtybdf/uQd/YfVR2r5pcbNuEYKzMQpcxmeSJw=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU=
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 h1:EyBZibRTVAs6ECHZOw5/wlylS9OcTzwyjeQMudmREjE=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1/go.mod h1:JKpmtYhhPs7D97NL/ltqz7yCkERFW5dOlHyVl66ZYF8=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.5 h1:K/NXvIftOlX+oGgWGIa3jDyYLDNsdVhsjHmsBH2GLAQ=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.5/go.mod h1:cl9HGLV66EnCmMNzq4sYOti+/xo8w34CsgzVtm2GgsY=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.2 h1:XOPfar83RIRPEzfihnp+U6udOveKZJvPQ76SKWrLRHc=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.2/go.mod h1:Vv9Xyk1KMHXrR3vNQe8W5LMFdTjSeWk0gBZBzvf3Qa0=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.2 h1:pi0Skl6mNl2w8qWZXcdOyg197Zsf4G97U7Sso9JXGZE=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.2/go.mod h1:JYzLoEVeLXk+L4tn1+rrkfhkxl6mLDEVaDSvGq9og90=
github.com/aws/aws-sdk-go-v2/service/sts v1.28.4 h1:Ppup1nVNAOWbBOrcoOxaxPeEnSFB2RnnQdguhXpmeQk=
github.com/aws/aws-sdk-go-v2/service/sts v1.28.4/go.mod h1:+K1rNPVyGxkRuv9NNiaZ4YhBFuyw2MMA9SlIJ1Zlpz8=
github.com/aws/constructs-go/constructs/v10 v10.3.0 h1:LsjBIMiaDX/vqrXWhzTquBJ9pPdi02/H+z1DCwg0PEM=
github.com/aws/constructs-go/constructs/v10 v10.3.0/go.mod h1:GgzwIwoRJ2UYsr3SU+JhAl+gq5j39bEMYf8ev3J+s9s=
github.com/aws/jsii-runtime-go v1.95.0 h1:I43Ye2AI8YNul6aWgtsvE76Vq6K6OzDEnZa/3g+sNtM=
github.com/aws/jsii-runtime-go v1.95.0/go.mod h1:ltYD/GbXiTKFeEUn03Ypwhl75N1Rwj4G2094XHjc+LM=
github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw=
github.com/aws/smithy-go v1.20.1/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.202 h1:VixXB9DnHN8oP7pXipq8GVFPjWCOdeNxIaS/ZyUwTkI=
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.202/go.mod h1:iPUti/SWjA3XAS3CpnLciFjS8TN9Y+8mdZgDfSgcyus=
github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.2 h1:k+WD+6cERd59Mao84v0QtRrcdZuuSMfzlEmuIypKnVs=
github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.2/go.mod h1:CvFHBo0qcg8LUkJqIxQtP1rD/sNGv9bX3L2vHT2FUAo=
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.0.1 h1:MBBQNKKPJ5GArbctgwpiCy7KmwGjHDjUUH5wEzwIq8w=
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.0.1/go.mod h1:/2WiXEft9s8ViJjD01CJqDuyJ8HXBjhBLtK5OvJfdSc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fogfish/faults v0.2.0 h1:3KHvZN3cgv2omAGw0MCVH/AbrqxfNag+TFGpgUp6m1w=
Expand All @@ -31,18 +58,21 @@ github.com/fogfish/gouldian/v2 v2.0.5 h1:ixk6WG/Is8HmphScmpkKZgNjVWXLUuqyEyuBp0j
github.com/fogfish/gouldian/v2 v2.0.5/go.mod h1:NRPBfFZnGmEOIIRIu9knukoFfrCKXFmXO6GR4MD+BOU=
github.com/fogfish/guid/v2 v2.0.4 h1:EZiPlM4UAghqf7DU5/nLEF+iRH7ODe0AiFuYOMRvITQ=
github.com/fogfish/guid/v2 v2.0.4/go.mod h1:KkZ5T4EE3BqWQJFZBPLSHV/tBe23Xq4KvuPfwtNtepU=
github.com/fogfish/gurl/v2 v2.8.2 h1:VB+3lsNg1i9XPm8pDVaZongNfk17NfS5FG2TFtTeLno=
github.com/fogfish/gurl/v2 v2.8.2/go.mod h1:VDPaGeyMSZsbFByZXwKZuwKgOC1mOQNlOYhM4RgOVWQ=
github.com/fogfish/gurl/awsapi v0.0.1 h1:rkMUq/DCVomHB69YwSlx0UdOG9uIxEJMZFfYbwphPpw=
github.com/fogfish/gurl/awsapi v0.0.1/go.mod h1:Hw/zYRqIAAHkV+63BA1kt1gTmdm8gF1Q+Kx9RST2cv0=
github.com/fogfish/gurl/v2 v2.8.3 h1:CH8dOHz+lMPg3M0/S5bWk5z3RD9FG4L8+uQMEv36ibU=
github.com/fogfish/gurl/v2 v2.8.3/go.mod h1:VDPaGeyMSZsbFByZXwKZuwKgOC1mOQNlOYhM4RgOVWQ=
github.com/fogfish/it v0.9.1/go.mod h1:NQJG4Ygvek85y7zGj0Gny8+6ygAnHjfBORhI7TdQhp4=
github.com/fogfish/it v1.0.0 h1:kiwFHZcrkRLUydZoIoY0gTuMfj38trwvLo0YRyIkeG8=
github.com/fogfish/it v1.0.0/go.mod h1:NQJG4Ygvek85y7zGj0Gny8+6ygAnHjfBORhI7TdQhp4=
github.com/fogfish/it/v2 v2.0.1 h1:vu3kV2xzYDPHoMHMABxXeu5CoMcTfRc4gkWkzOUkRJY=
github.com/fogfish/it/v2 v2.0.1/go.mod h1:h5FdKaEQT4sUEykiVkB8VV4jX27XabFVeWhoDZaRZtE=
github.com/fogfish/logger v1.1.0 h1:IZncrh4+Q7yyngcIq8lBr2VwcYE2huXcgCPKcT+zPOY=
github.com/fogfish/logger v1.1.0/go.mod h1:o9Url3zZMjg87bOJKZTdWIX3aRmClY+3Ld97Jc2Podg=
github.com/fogfish/schemaorg v1.22.0 h1:0laPbToW8lVxdx7hPgc8qukZfrewBJYNf4ffpZn/6HQ=
github.com/fogfish/schemaorg v1.22.0/go.mod h1:CDOmEVSdag/o66Y3qjFROm0mUjJxDvSzAOXQwd+ZFrs=
github.com/fogfish/scud v0.6.0 h1:sJsWAvvRcX4kRYYUXbOTw9hyZV+ax01TxpXlHKeTJGg=
github.com/fogfish/scud v0.6.0/go.mod h1:7EH9GAGQK4oux9sTMhtSEfEVbism2ED+2gTb/UNFqvs=
github.com/fogfish/scud v0.7.1 h1:BDkvmjaA/u3QKlge2KuNTtMODPFXXrIUDp8MAlp7VAM=
github.com/fogfish/scud v0.7.1/go.mod h1:Y2dpXsD8KlrOJoS7HL6HL5OOC87TY4i229ePXPlx3bQ=
github.com/fogfish/skiplist v0.15.0 h1:o3f6I20LsT4D17Vf9eyNyFd5CCGOXo147x1DSi4RbpE=
github.com/fogfish/skiplist v0.15.0/go.mod h1:giiFtWK+lmnpgQQJzWFydHoTTGRzP+8kcBsKoS30iO8=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
Expand All @@ -55,7 +85,9 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU=
github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand All @@ -75,6 +107,7 @@ golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -97,3 +130,4 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
53 changes: 53 additions & 0 deletions http/curl/petshop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package curl

import (
"context"

"github.com/fogfish/blueprint-serverless-golang/http/api"
"github.com/fogfish/gurl/v2/http"
ƒ "github.com/fogfish/gurl/v2/http/recv"
ø "github.com/fogfish/gurl/v2/http/send"
"github.com/fogfish/schemaorg"
)

type PetShop struct {
http.Stack
host ø.Authority
}

func NewPetShop(stack http.Stack, host string) *PetShop {
return &PetShop{
Stack: stack,
host: ø.Authority(host),
}
}

func (c *PetShop) List(ctx context.Context) (*api.Pets, error) {
return http.IO[api.Pets](c.WithContext(ctx),
http.GET(
ø.URI("%s/petshop/pets", c.host),
ø.Accept.ApplicationJSON,
ƒ.Status.OK,
),
)
}

func (c *PetShop) Continue(ctx context.Context, cursor schemaorg.Url) (*api.Pets, error) {
return http.IO[api.Pets](c.WithContext(ctx),
http.GET(
ø.URI("%s%s", c.host, ø.Path(cursor)),
ø.Accept.ApplicationJSON,
ƒ.Status.OK,
),
)
}

func (c *PetShop) Pet(ctx context.Context, url schemaorg.Url) (*api.Pet, error) {
return http.IO[api.Pet](c.WithContext(ctx),
http.GET(
ø.URI("%s%s", c.host, ø.Path(url)),
ø.Accept.ApplicationJSON,
ƒ.Status.OK,
),
)
}
26 changes: 15 additions & 11 deletions http/endpoints.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package http

import (
"fmt"
µ "github.com/fogfish/gouldian/v2"
"net/http"
)

// Customer Endpoint
func AllowSecretCode() µ.Endpoint {
return µ.Authorization(
func(kind, digest string) error {
if kind != "Basic" {
return µ.ErrNoMatch
}
return func(ctx *µ.Context) error {
code := ctx.Request.Header.Get("X-Secret-Code")
if code == "" {
out := µ.NewOutput(http.StatusUnauthorized)
out.SetIssue(fmt.Errorf("unauthorized %s", ctx.Request.URL.Path))
return out
}

if digest != "cGV0c3RvcmU6b3duZXIK" {
return µ.ErrNoMatch
}
if code != "cGV0c3RvcmU6b3duZXIK" {
return µ.ErrNoMatch
}

return nil
},
)
return nil
}
}
2 changes: 0 additions & 2 deletions http/petshop.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

//go:generate mockgen -destination ../mock/petshop.go -package mock . PetFetcher,PetCreator

type PetFetcher interface {
LookupPet(context.Context, core.Identity) (core.Pet, error)
LookupPetsAfterKey(context.Context, core.Identity, int) ([]core.Pet, error)
Expand Down Expand Up @@ -60,7 +59,6 @@ func (shop PetShopAPI) List() µ.Routable {
pets := api.NewPets(petSeqN, seq)
return ø.Status.OK(
ø.ContentType.ApplicationJSON,
// ø.L
ø.Send(pets),
)
default:
Expand Down
Loading

0 comments on commit f49eaf9

Please sign in to comment.