Skip to content

Commit

Permalink
Guilty. Didn't go fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincetse committed Dec 2, 2017
1 parent bee9630 commit bb6e9ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
40 changes: 20 additions & 20 deletions hello_world.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@ package main

import (
"net/http"
"os"
"os"

"github.com/gin-gonic/gin"
"github.com/zsais/go-gin-prometheus"
"github.com/gin-gonic/gin"
"github.com/zsais/go-gin-prometheus"
)

var hostname = getHostname()

func getHostname() string {
var name, err = os.Hostname()
if err != nil {
panic(err)
}
return name
var name, err = os.Hostname()
if err != nil {
panic(err)
}
return name
}

func helloFunc(c *gin.Context) {
c.Writer.Header().Set("X-Hostname", hostname)
c.String(http.StatusOK, "Hello, World!")
c.Writer.Header().Set("X-Hostname", hostname)
c.String(http.StatusOK, "Hello, World!")
}

func healthFunc(c *gin.Context) {
c.Writer.Header().Set("X-Hostname", hostname)
c.String(http.StatusOK, "")
c.Writer.Header().Set("X-Hostname", hostname)
c.String(http.StatusOK, "")
}

func setupRouter() *gin.Engine {
router := gin.Default()
ginprom := ginprometheus.NewPrometheus("gin")
ginprom.Use(router)
router.GET("/", helloFunc)
router.GET("/health", healthFunc)
return router
router := gin.Default()
ginprom := ginprometheus.NewPrometheus("gin")
ginprom.Use(router)
router.GET("/", helloFunc)
router.GET("/health", healthFunc)
return router
}

func main() {
router := setupRouter()
router.Run()
router := setupRouter()
router.Run()
}
13 changes: 6 additions & 7 deletions hello_world_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package main

import (
Expand All @@ -10,33 +9,33 @@ import (
)

func TestDefaultRoute(t *testing.T) {
router := setupRouter()
router := setupRouter()

w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/", nil)
router.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
assert.Equal(t, 200, w.Code)
assert.Equal(t, "Hello, World!", w.Body.String())
}

func TestHealthRoute(t *testing.T) {
router := setupRouter()
router := setupRouter()

w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/health", nil)
router.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
assert.Equal(t, 200, w.Code)
assert.Equal(t, "", w.Body.String())
}

func TestMetricsRoute(t *testing.T) {
router := setupRouter()
router := setupRouter()

w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/metrics", nil)
router.ServeHTTP(w, req)

assert.Equal(t, 200, w.Code)
assert.Equal(t, 200, w.Code)
}

0 comments on commit bb6e9ac

Please sign in to comment.