Giter Site home page Giter Site logo

learningbyexample / go-microservice Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 193 KB

A educational project for creating a microservice in go

License: Apache License 2.0

Go 95.37% Makefile 2.01% Shell 2.46% Dockerfile 0.16%
go golang micro-service microservice

go-microservice's People

Contributors

fanycastro avatar juan-medina avatar

Watchers

 avatar  avatar  avatar

go-microservice's Issues

all store methods should return an error

All store method should return an error, with this we could prepare better for stores that are more complex than the in-memory datastore

type PetStore interface {
AddPet(name string, race string, mod string) int
GetPet(id int) (data.Pet, error)
GetAllPets() []data.Pet
DeletePet(id int) error
UpdatePet(id int, name string, race string, mod string) (bool, error)
}

Get list

we should have a get all the pets in our store

Bad port test is stack when running tests

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"
	}
}

Implement PUT

We currently have POST but we need to implement PUT

adding go vet

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

Implement PostgreSQL datastore

We should implement a PostgreSQL.

  • create a new pet store
  • create a new provider
  • add default config files
  • mock database

concurrency bug in in memory data store

I've added a new test, currently skipped, that shows a concurrency problem on in memory data store

func TestConcurrency(t *testing.T) {
t.Skipf("skiping test, need to fix concurrency")
ps := NewInMemoryPetStore()
wantedCount := 1000
var wg sync.WaitGroup
wg.Add(wantedCount)
for i := 0; i < wantedCount; i++ {
go func(w *sync.WaitGroup) {
seqName := fmt.Sprintf("Fluff%d", wantedCount)
id := ps.AddPet(seqName, "dog", "happy")
_, _ = ps.GetPet(id)
newName := fmt.Sprintf("Fluffy%d", wantedCount)
_, _ = ps.UpdatePet(id, newName, "dog", "happy")
_, _ = ps.GetPet(id)
_ = ps.GetAllPets()
_ = ps.DeletePet(id)
_ = ps.GetAllPets()
w.Done()
}(&wg)
}
wg.Wait()
total := len(ps.GetAllPets())
wantTotal := 0
if total != wantTotal {
t.Fatalf("want %q, got %v", wantTotal, total)
}
}

GET on /pet/1 log superflous write header

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)

Better HTTP responses

currently when validating a pet we just a generic error, we should get the fields that are not ok in the validation

Add graceful shutdown

In order to behave propertly we need to handle a gracefult shutdown of the server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.