Skip to content

Commit

Permalink
Updated dependencies (moved to urfave repos, lowercase sirupsen/logru…
Browse files Browse the repository at this point in the history
…s), removed gorilla/context and moved to go context, moved logging to stdout and added Dockerfile
  • Loading branch information
brandonvfx committed Jul 12, 2017
1 parent 5c20b14 commit 267c762
Show file tree
Hide file tree
Showing 29 changed files with 252 additions and 168 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ _testmain.go
gin-bin
sg-restful

Godeps/_workspace
Godeps/_workspace
tasks.json
*.log
vendor
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:latest

WORKDIR /go/src/app
COPY . .

# "gogo"
RUN go-wrapper download
# "go install -v ./..."
#CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
ENV CGO_ENABLED 0
ENV GOOS linux
RUN go-wrapper install -a -installsuffix cgo

FROM scratch
COPY --from=0 /go/bin/app .
CMD ["/app"]
71 changes: 47 additions & 24 deletions Godeps/Godeps.json

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

8 changes: 4 additions & 4 deletions entity_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (
"net/http"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/gorilla/context"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)

type createResponse struct {
Expand Down Expand Up @@ -66,8 +65,9 @@ func entityCreateHandler(config clientConfig) func(rw http.ResponseWriter, req *
"fields": fields,
}

sgConn, ok := context.GetOk(req, "sgConn")
if !ok {
ctx := req.Context()
sgConn := ctx.Value("sgConn")
if sgConn == nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
27 changes: 16 additions & 11 deletions entity_create_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

"github.com/gorilla/context"
"github.com/stretchr/testify/assert"
)

Expand All @@ -20,8 +20,9 @@ func TestCreateBadRequestJson(t *testing.T) {
server, client, config := mockShotgun(200, `foo`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusBadRequest, w.Code)
}

Expand All @@ -35,8 +36,9 @@ func TestCreateSimple(t *testing.T) {
server, client, config := mockShotgun(200, `{"results":{"id":75,"name":"My Project","type":"Project"}}`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusCreated, w.Code)

type Entity struct {
Expand Down Expand Up @@ -71,8 +73,9 @@ func TestCreateConflict(t *testing.T) {
`{"exception":true,"message":"API create() CRUD ERROR #61: Create failed for [Project]. The value for the Project Name field is required to be unique. <br>","error_code":104}`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusConflict, w.Code)
}

Expand All @@ -86,8 +89,9 @@ func TestCreateBadResponseJson(t *testing.T) {
server, client, config := mockShotgun(200, `foo`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusBadGateway, w.Code)
}

Expand All @@ -102,7 +106,8 @@ func TestCreateShotgunError(t *testing.T) {
`{"exception":true,"message":"API create() CRUD ERROR Some other error","error_code":104}`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusBadRequest, w.Code)
}
8 changes: 4 additions & 4 deletions entity_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (
"strconv"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/gorilla/context"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)

type deleteResponse struct {
Expand Down Expand Up @@ -51,8 +50,9 @@ func entityDeleteHandler(config clientConfig) func(rw http.ResponseWriter, req *
"id": entityID,
}

sgConn, ok := context.GetOk(req, "sgConn")
if !ok {
ctx := req.Context()
sgConn := ctx.Value("sgConn")
if sgConn == nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
32 changes: 19 additions & 13 deletions entity_delete_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/gorilla/context"
"github.com/stretchr/testify/assert"
)

Expand All @@ -17,8 +17,9 @@ func TestDeleteNoId(t *testing.T) {
server, client, config := mockShotgun(200, `foo`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusNotFound, w.Code)
}

Expand All @@ -34,8 +35,9 @@ func TestDeletePermissionsIssue(t *testing.T) {
`[\"Template Project\"]}","error_code":104}`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusForbidden, w.Code)
}

Expand All @@ -48,8 +50,9 @@ func TestDeleteError(t *testing.T) {
`{"exception":true,"message":"Somer Error message","error_code":104}`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusBadRequest, w.Code)
}

Expand All @@ -61,8 +64,9 @@ func TestDeleteSuccess(t *testing.T) {
server, client, config := mockShotgun(200, `{"results": true}`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusOK, w.Code)
}

Expand All @@ -75,8 +79,9 @@ func TestDeleteMissing(t *testing.T) {
`{"exception":true,"message":"API delete() CRUD ERROR #3: Entity of type [Shot] with id=1000000 does not exist.","error_code":104}`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusNotFound, w.Code)
}

Expand All @@ -88,7 +93,8 @@ func TestDeleteBadJsonResponse(t *testing.T) {
server, client, config := mockShotgun(200, `foo`)
defer server.Close()

context.Set(req, "sgConn", *client)
router(config).ServeHTTP(w, req)
ctx := req.Context()
ctx = context.WithValue(ctx, "sgConn", *client)
router(config).ServeHTTP(w, req.WithContext(ctx))
assert.Equal(t, http.StatusBadGateway, w.Code)
}
8 changes: 4 additions & 4 deletions entity_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import (
"strconv"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/gorilla/context"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)

func entityGetHandler(config clientConfig) func(rw http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -72,8 +71,9 @@ func entityGetHandler(config clientConfig) func(rw http.ResponseWriter, req *htt

log.Debug(query)

sgConn, ok := context.GetOk(req, "sgConn")
if !ok {
ctx := req.Context()
sgConn := ctx.Value("sgConn")
if sgConn == nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
8 changes: 4 additions & 4 deletions entity_get_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
"strconv"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/gorilla/context"
"github.com/gorilla/mux"
log "github.com/sirupsen/logrus"
)

// Response Structs
Expand Down Expand Up @@ -175,8 +174,9 @@ func entityGetAllHandler(config clientConfig) func(rw http.ResponseWriter, req *

log.Debugf("Query: %v", StructToString(query))

sgConn, ok := context.GetOk(req, "sgConn")
if !ok {
ctx := req.Context()
sgConn := ctx.Value("sgConn")
if sgConn == nil {
rw.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
Loading

0 comments on commit 267c762

Please sign in to comment.