Skip to content

Commit

Permalink
Merge branch 'release/0.4.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
takama committed Oct 21, 2017
2 parents 5c0e18a + 037b076 commit 98d488e
Show file tree
Hide file tree
Showing 24 changed files with 74 additions and 1,620 deletions.
10 changes: 8 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@

[[constraint]]
name = "github.com/kelseyhightower/envconfig"
revision = "70f0258d44cbaa3b6a2581d82f58da01a38e4de4"
revision = "462fda1f11d8cad3660e52737b8beefd27acfb3f"

[[constraint]]
name = "github.com/takama/bit"
version = "0.2.3"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ REGISTRY?=docker.io/takama
CA_DIR?=certs

# Use the 0.0.0 tag for testing, it shouldn't clobber any release builds
RELEASE?=0.4.5
RELEASE?=0.4.6
GOOS?=linux
GOARCH?=amd64

Expand Down
2 changes: 1 addition & 1 deletion charts/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: k8sapp
description: A Helm charts for Kubernetes application
version: 0.4.5
version: 0.4.6
home: https://my.domain/
sources:
- https://github.com/takama/k8sapp
Expand Down
2 changes: 1 addition & 1 deletion charts/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ image:
##
registry: docker.io/takama
name: k8sapp
tag: 0.4.5
tag: 0.4.6

## Docker Registry/Hub auth secret name, always use `registry-pull-secret` if registry inside if k8s
##
Expand Down
2 changes: 1 addition & 1 deletion charts/values-stable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ image:
##
registry: docker.io/takama
name: k8sapp
tag: 0.4.5
tag: 0.4.6

## Docker Registry/Hub auth secret name, always use `registry-pull-secret` if registry inside if k8s
##
Expand Down
9 changes: 8 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Version 0.4.5
# Version 0.4.6

[Documentation](README.md)


## Changelog since 0.4.5

### Codebase

- Released #34: move embedded http router into external package ([#39](https://github.com/takama/k8sapp/pull/39), [@takama](https://github.com/takama))

## Changelog since 0.4.4

### Codebase
Expand Down
12 changes: 7 additions & 5 deletions pkg/handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"net/http"
"time"

"github.com/takama/bit"
// Alternative of the Bit router with the same Router interface
// "github.com/takama/k8sapp/pkg/router/httprouter"
"github.com/takama/k8sapp/pkg/config"
"github.com/takama/k8sapp/pkg/logger"
"github.com/takama/k8sapp/pkg/router"
"github.com/takama/k8sapp/pkg/version"
)

Expand Down Expand Up @@ -45,8 +47,8 @@ func New(logger logger.Logger, config *config.Config) *Handler {
}

// Base handler implements middleware logic
func (h *Handler) Base(handle func(router.Control)) func(router.Control) {
return func(c router.Control) {
func (h *Handler) Base(handle func(bit.Control)) func(bit.Control) {
return func(c bit.Control) {
timer := time.Now()
handle(c)
h.countDuration(timer)
Expand All @@ -55,7 +57,7 @@ func (h *Handler) Base(handle func(router.Control)) func(router.Control) {
}

// Root handler shows version
func (h *Handler) Root(c router.Control) {
func (h *Handler) Root(c bit.Control) {
c.Code(http.StatusOK)
c.Body(fmt.Sprintf("%s v%s", config.SERVICENAME, version.RELEASE))
}
Expand All @@ -75,7 +77,7 @@ func (h *Handler) countDuration(timer time.Time) {
}
}

func (h *Handler) collectCodes(c router.Control) {
func (h *Handler) collectCodes(c bit.Control) {
if c.GetCode() >= 500 {
h.stats.requests.Codes.C5xx++
} else {
Expand Down
15 changes: 8 additions & 7 deletions pkg/handlers/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import (
"net/http/httptest"
"testing"

"github.com/takama/bit"
// Alternative of the Bit router with the same Router interface
// "github.com/takama/k8sapp/pkg/router/httprouter"
"github.com/takama/k8sapp/pkg/config"
"github.com/takama/k8sapp/pkg/logger"
"github.com/takama/k8sapp/pkg/logger/standard"
"github.com/takama/k8sapp/pkg/router"
"github.com/takama/k8sapp/pkg/router/bitroute"
"github.com/takama/k8sapp/pkg/version"
)

func TestRoot(t *testing.T) {
h := New(standard.New(&logger.Config{}), new(config.Config))
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.Base(h.Root)(bitroute.NewControl(w, r))
h.Base(h.Root)(bit.NewControl(w, r))
})

testHandler(t, handler, http.StatusOK, fmt.Sprintf("%s v%s", config.SERVICENAME, version.RELEASE))
Expand All @@ -43,18 +44,18 @@ func testHandler(t *testing.T, handler http.HandlerFunc, code int, body string)
func TestCollectCodes(t *testing.T) {
h := New(standard.New(&logger.Config{}), new(config.Config))
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.Base(func(c router.Control) {
h.Base(func(c bit.Control) {
c.Code(http.StatusBadGateway)
c.Body(http.StatusText(http.StatusBadGateway))
})(bitroute.NewControl(w, r))
})(bit.NewControl(w, r))
})
testHandler(t, handler, http.StatusBadGateway, http.StatusText(http.StatusBadGateway))

handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.Base(func(c router.Control) {
h.Base(func(c bit.Control) {
c.Code(http.StatusNotFound)
c.Body(http.StatusText(http.StatusNotFound))
})(bitroute.NewControl(w, r))
})(bit.NewControl(w, r))
})
testHandler(t, handler, http.StatusNotFound, http.StatusText(http.StatusNotFound))
}
6 changes: 4 additions & 2 deletions pkg/handlers/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ package handlers
import (
"net/http"

"github.com/takama/k8sapp/pkg/router"
"github.com/takama/bit"
// Alternative of the Bit router with the same Router interface
// "github.com/takama/k8sapp/pkg/router/httprouter"
)

// Health returns "OK" if service is alive
func (h *Handler) Health(c router.Control) {
func (h *Handler) Health(c bit.Control) {
c.Code(http.StatusOK)
c.Body(http.StatusText(http.StatusOK))
}
6 changes: 4 additions & 2 deletions pkg/handlers/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import (
"net/http"
"testing"

"github.com/takama/bit"
// Alternative of the Bit router with the same Router interface
// "github.com/takama/k8sapp/pkg/router/httprouter"
"github.com/takama/k8sapp/pkg/config"
"github.com/takama/k8sapp/pkg/logger"
"github.com/takama/k8sapp/pkg/logger/standard"
"github.com/takama/k8sapp/pkg/router/bitroute"
)

func TestHealth(t *testing.T) {
h := New(standard.New(&logger.Config{}), new(config.Config))
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.Base(h.Health)(bitroute.NewControl(w, r))
h.Base(h.Health)(bit.NewControl(w, r))
})

testHandler(t, handler, http.StatusOK, http.StatusText(http.StatusOK))
Expand Down
6 changes: 4 additions & 2 deletions pkg/handlers/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"runtime"
"time"

"github.com/takama/k8sapp/pkg/router"
"github.com/takama/bit"
// Alternative of the Bit router with the same Router interface
// "github.com/takama/k8sapp/pkg/router/httprouter"
"github.com/takama/k8sapp/pkg/version"
)

Expand Down Expand Up @@ -60,7 +62,7 @@ type Codes struct {
}

// Info returns detailed info about the service
func (h *Handler) Info(c router.Control) {
func (h *Handler) Info(c bit.Control) {
host, _ := os.Hostname()
m := new(runtime.MemStats)
runtime.ReadMemStats(m)
Expand Down
6 changes: 4 additions & 2 deletions pkg/handlers/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import (
"net/http/httptest"
"testing"

"github.com/takama/bit"
// Alternative of the Bit router with the same Router interface
// "github.com/takama/k8sapp/pkg/router/httprouter"
"github.com/takama/k8sapp/pkg/config"
"github.com/takama/k8sapp/pkg/logger"
"github.com/takama/k8sapp/pkg/logger/standard"
"github.com/takama/k8sapp/pkg/router/bitroute"
"github.com/takama/k8sapp/pkg/version"
)

func TestInfo(t *testing.T) {
h := New(standard.New(&logger.Config{}), new(config.Config))
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.Base(h.Info)(bitroute.NewControl(w, r))
h.Base(h.Info)(bit.NewControl(w, r))
})

req, err := http.NewRequest("GET", "/", nil)
Expand Down
6 changes: 4 additions & 2 deletions pkg/handlers/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ package handlers
import (
"net/http"

"github.com/takama/k8sapp/pkg/router"
"github.com/takama/bit"
// Alternative of the Bit router with the same Router interface
// "github.com/takama/k8sapp/pkg/router/httprouter"
)

// Ready returns "OK" if service is ready to serve traffic
func (h *Handler) Ready(c router.Control) {
func (h *Handler) Ready(c bit.Control) {
// TODO: possible use cases:
// load data from a database, a message broker, any external services, etc

Expand Down
6 changes: 4 additions & 2 deletions pkg/handlers/ready_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ import (
"net/http"
"testing"

"github.com/takama/bit"
// Alternative of the Bit router with the same Router interface
// "github.com/takama/k8sapp/pkg/router/httprouter"
"github.com/takama/k8sapp/pkg/config"
"github.com/takama/k8sapp/pkg/logger"
"github.com/takama/k8sapp/pkg/logger/standard"
"github.com/takama/k8sapp/pkg/router/bitroute"
)

func TestReady(t *testing.T) {
h := New(standard.New(&logger.Config{}), new(config.Config))
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h.Base(h.Ready)(bitroute.NewControl(w, r))
h.Base(h.Ready)(bit.NewControl(w, r))
})

testHandler(t, handler, http.StatusOK, http.StatusText(http.StatusOK))
Expand Down
86 changes: 0 additions & 86 deletions pkg/router/bitroute.go

This file was deleted.

Loading

0 comments on commit 98d488e

Please sign in to comment.