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
No service can be considered production-ready without thorough logging and instrumentation.
197
197
198
+
## Seperation of concerns
199
+
200
+
Separating each layer of the call graph into individual files makes a go-kit project easier to read as you increase the number of service endpoints. Our first example [stringsvc1](https://github.com/go-kit/kit/blob/master/examples/stringsvc1) had all of these layers in a single main file. Before we had more complexity separate your code into the following files and leave all remaining code in main.go
201
+
202
+
Place your **services** into a service.go file with the following functions and types.
203
+
204
+
```
205
+
type StringService
206
+
func stringService
207
+
var ErrEmpty
208
+
```
209
+
210
+
Place your **transports** into a transport.go file with the following functions and types.
211
+
212
+
```
213
+
func makeUppercaseEndpoint
214
+
func makeCountEndpoint
215
+
func decodeUppercaseRequest
216
+
func decodeCountRequest
217
+
func encodeResponse
218
+
type uppercaseRequest
219
+
type uppercaseResponse
220
+
type countRequest
221
+
type countResponse
222
+
```
223
+
198
224
## Transport logging
199
225
200
226
Any component that needs to log should treat the logger like a dependency, same as a database connection.
Use the [go-kit log](https://gokit.io/faq/#logging-mdash-why-is-package-log-so-different) package and remove the standard libraries [log](https://golang.org/pkg/log/). You will need to remove `log.Fatal` from main.go
0 commit comments