go-kit/

directory
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2017 License: MIT

README

Example - Go kit

Go Kit is an excellent framework for building microservices.

The following example is a simple Login UI (Consumer) that calls a User Service (Provider) using JSON over HTTP.

The API currently exposes a single Login endpoint at POST /users/login, which the Consumer uses to authenticate a User.

We test 3 scenarios, highlighting the use of Provider States:

  1. When the user "Billy" exists, and we perform a login, we expect an HTTP 200
  2. When the user "Billy" does not exists, and we perform a login, we expect an HTTP 404
  3. When the user "Billy" is unauthorized, and we perform a login, we expect an HTTP 403

Getting started

Before any of these tests can be run, ensure Pact Go is installed and run the daemon in the background:

go get ./...
<path to>/pact-go daemon

Provider

The "Provider" is a real Go Kit Endpoint (following the Profile Service example), exposing a single /users/login API call:

cd provider
go test -v .

This will spin up the Provider API with extra routes added for the handling of provider states, run the verification process and report back success/failure.

Running the Provider

The provider can be run as a standalone service:

go run cmd/usersvc/main.go

# 200
curl -v -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
  "username":"billy",
  "password":"issilly"
}' "http://localhost:8080/users/login"

# 403
curl -v -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
  "username":"billy",
  "password":"issilly"
}' "http://localhost:8080/users/login"

# 404
curl -v -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
  "username":"someoneelse",
  "password":"issilly"
}' "http://localhost:8080/users/login"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL