Skip to content

Commit ffb0d04

Browse files
committed
Code cleanup
1 parent 1860af8 commit ffb0d04

File tree

6 files changed

+8
-61
lines changed

6 files changed

+8
-61
lines changed

golang-coprocessor/README.md

+4-16
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,12 @@ Modeled after the ["Server project"](https://go.dev/doc/modules/layout) layout
1010

1111
## Run
1212

13-
1. Pick one of the Golang frameworks exampled under `cmd`. Customers often have a "platform" preferred one they write other services in.
1413
1. Start the coprocessor
15-
```shell
16-
go run cmd/simple-http/main.go
17-
```
18-
or
19-
```shell
20-
go run cmd/gorilla-mux/main.go
21-
```
22-
... etc.
14+
```shell
15+
go run cmd/simple-http/main.go
16+
```
2317
1. [Start the router](/router/README.md#running-the-router)
2418

25-
## Packaging for a customer
26-
27-
1. Copy whole directory
28-
1. Remove unnecessary `cmd`'s
29-
1. Run `go mod tidy` which will cleanup the imports for all the other frameworks
30-
3119
## Logging types
3220

33-
https://go.dev/play/p/yHGoKST0lEx
21+
https://go.dev/play/p/yHGoKST0lEx

golang-coprocessor/cmd/gorilla-mux/main.go

-39
This file was deleted.

golang-coprocessor/go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
)
1010

1111
require (
12-
github.com/gorilla/mux v1.8.1
1312
github.com/mattn/go-colorable v0.1.13 // indirect
1413
github.com/mattn/go-isatty v0.0.19 // indirect
1514
github.com/pkg/errors v0.9.1 // indirect

golang-coprocessor/go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ4
44
github.com/go-logr/zerologr v1.2.3 h1:up5N9vcH9Xck3jJkXzgyOxozT14R47IyDODz8LM1KSs=
55
github.com/go-logr/zerologr v1.2.3/go.mod h1:BxwGo7y5zgSHYR1BjbnHPyF/5ZjVKfKxAZANVu6E8Ho=
66
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
7-
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
8-
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
97
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
108
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
119
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=

golang-coprocessor/internal/stages.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ func HandleRequest(w http.ResponseWriter, r *http.Request) (interface{}, error)
1313
return nil, fmt.Errorf("error unmarshaling httpRequestBody: %w", err)
1414
}
1515

16+
// Add more stages here as needed as per the docs: https://www.apollographql.com/docs/router/customizations/coprocessor/#stage
1617
switch stage {
1718
case "RouterRequest":
1819
return handleRouterRequest(httpRequestBody)

golang-coprocessor/internal/stages_router.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (rr *RouterRequest) MarshalJSON() ([]byte, error) {
101101
jsonBody, err = json.Marshal(rr.Body)
102102

103103
if err != nil {
104-
logger.Error(err, "failed to marshal coprocessor request string into struct: %v")
104+
logger.Error(err, "failed to marshal coprocessor request struct: %v")
105105
}
106106

107107
routerRequestBodyOverride.Body = string(jsonBody)
@@ -198,7 +198,7 @@ func (rr *RouterResponse) MarshalJSON() ([]byte, error) {
198198
jsonBody, err = json.Marshal(rr.Body)
199199

200200
if err != nil {
201-
logger.Error(err, "failed to marshal coprocessor request string into struct: %v")
201+
logger.Error(err, "failed to marshal coprocessor request struct: %v")
202202
}
203203

204204
routerRequestBodyOverride.Body = string(jsonBody)
@@ -219,7 +219,7 @@ func handleRouterRequest(httpRequestBody *[]byte) (*RouterRequest, error) {
219219
requestBody, err := json.Marshal(cr)
220220

221221
if err != nil {
222-
logger.Error(err, "failed to unmarshal coprocessor request string into struct: %v")
222+
logger.Error(err, "failed to marshal coprocessor request struct: %v")
223223
}
224224

225225
// This is the object sent by the Router that you can act upon to update headers, context, auth claims, etc

0 commit comments

Comments
 (0)