learningbyexample / go-microservice Goto Github PK
View Code? Open in Web Editor NEWA educational project for creating a microservice in go
License: Apache License 2.0
A educational project for creating a microservice in go
License: Apache License 2.0
All store method should return an error, with this we could prepare better for stores that are more complex than the in-memory datastore
go-microservice/internal/app/store/store.go
Lines 30 to 36 in 013cf2b
In we want to deploy this service in a k8s cluster we need to have liveness and readiness endpoints
we should have a get all the pets in our store
we need a way to have configuration arguments
follow this structure
In the bad.port.json the port 49 is a problem when we run the tests. We should change it to avoid tests stack.
{
"server": {
"port": 49
},
"store": {
"name": "in-memory"
}
}
We currently have POST but we need to implement PUT
When we get an error during a request we should see the trace in the server log.
Currently, we are not running go vet, and we should, in fact, we have a couple of go vet errors already
$ go vet ./internal/app/...
# github.com/LearningByExample/go-microservice/internal/app/store/memory
internal/app/store/memory/memory.go:107:9: Open passes lock by value: github.com/LearningByExample/go-microservice/internal/app/store/memory.inMemoryPetStore contains sync.RWMutex
internal/app/store/memory/memory.go:112:9: Close passes lock by value: github.com/LearningByExample/go-microservice/internal/app/store/memory.inMemoryPetStore contains sync.RWMutex
since we use only the len of the map the id is incorrect, we need to use a lastId
value as before
the code coverage is quite low in some areas, we should improve it
We should implement a PostgreSQL.
I've added a new test, currently skipped, that shows a concurrency problem on in memory data store
go-microservice/internal/app/store/memory/memory_test.go
Lines 215 to 244 in 013cf2b
We should fix the array order. This is a reference to take into account to fix it:
https://golang.org/pkg/sort/
func (s *inMemoryPetStore) GetAllPets() ([]data.Pet, error) {
s.mu.RLock()
defer s.mu.RUnlock()
result := make([]data.Pet, 0, len(s.pets))
for k := range s.pets {
result = append(result, s.pets[k])
}
return result, nil
}
Now that we have an assert function for validating errors :
go-microservice/server/pet_test.go
Line 205 in d470e8e
We should create a new function for validating OK responses
We need on the README HTTPie example requests
We like to have a k8s deployment for this service
When doing a GET on a resource
$ http :8080/pet/1
we get on the log :
2020/02/16 17:05:03 http: superfluous response.WriteHeader call from github.com/LearningByExample/go-microservice/server.petHandler.ServeHTTP (pet.go:132)
Currently, the handler test use mostly InMemoryStore, it should use the SpyStore
The Server Tests use the InMemoryStore
go-microservice/server/server_test.go
Line 26 in 772df75
We should as well refactor the tests to make our helpers and spy reusable
when we run the server and is already running the application exit without erroring
we need a configuration file for handling things such connections
currently when validating a pet we just a generic error, we should get the fields that are not ok in the validation
With test containers, we could run the integration test against a real PSQL and as well in Travis
we need to add the connection pool settings for a database
In order to behave propertly we need to handle a gracefult shutdown of the server
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.