Skip to content

Commit

Permalink
go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Dino Omanovic committed Jun 20, 2016
1 parent 6fd3c31 commit ee1aad4
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion composition/composition_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (agg *CompositionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

} else if res.Def.Required {
log.WithField("fetchResult", res).Errorf("error loading content from: %v", res.Def.URL)
res.Def.ErrHandler.Handle(res.Err, res.HttpStatus, w, r)
res.Def.ErrHandler.Handle(res.Err, res.HttpStatus, w, r)
return
} else {
log.WithField("fetchResult", res).Warnf("optional content not loaded: %v", res.Def.URL)
Expand Down
6 changes: 3 additions & 3 deletions composition/composition_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ func Test_CompositionHandler_ErrorInFetching(t *testing.T) {
contentFetcherFactory := func(r *http.Request) FetchResultSupplier {
return MockFetchResultSupplier{
&FetchResult{
Def: NewFetchDefinition("/foo"),
Content: nil,
Err: errors.New(errorString),
Def: NewFetchDefinition("/foo"),
Content: nil,
Err: errors.New(errorString),
HttpStatus: 502,
},
}
Expand Down
12 changes: 6 additions & 6 deletions composition/content_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"sync"

"github.com/tarent/lib-compose/logging"
"strings"
"net/http"
"strings"
)

// IsFetchable returns, whether the fetch definition refers to a fetchable resource
Expand All @@ -16,11 +16,11 @@ func (def *FetchDefinition) IsFetchable() bool {
}

type FetchResult struct {
Def *FetchDefinition
Err error
Content Content
Def *FetchDefinition
Err error
Content Content
HttpStatus int
Hash string // the hash of the FetchDefinition
Hash string // the hash of the FetchDefinition
}

// ContentFetcher is a type, which can fetch a set of Content pages in parallel.
Expand Down Expand Up @@ -77,7 +77,7 @@ func (fetcher *ContentFetcher) AddFetchJob(d *FetchDefinition) {

fetcher.activeJobs.Add(1)

fetchResult := &FetchResult{Def: d, Hash: hash, Err: errors.New("not fetched"), HttpStatus:http.StatusBadGateway}
fetchResult := &FetchResult{Def: d, Hash: hash, Err: errors.New("not fetched"), HttpStatus: http.StatusBadGateway}
fetcher.r.results = append(fetcher.r.results, fetchResult)

go func() {
Expand Down
2 changes: 1 addition & 1 deletion composition/fetch_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,5 @@ func NewDefaultErrorHandler() *DefaultErrorHandler {
}

func (der *DefaultErrorHandler) Handle(err error, status int, w http.ResponseWriter, r *http.Request) {
http.Error(w, "Error: " + err.Error(), status)
http.Error(w, "Error: "+err.Error(), status)
}
2 changes: 1 addition & 1 deletion composition/fetch_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ func Test_FetchDefinition_use_DefaultErrorHandler_if_not_set(t *testing.T) {
a := assert.New(t)

fd := NewFetchDefinitionWithErrorHandler("http://upstream:8080/", nil)
a.Equal(NewDefaultErrorHandler(), fd.ErrHandler)
a.Equal(NewDefaultErrorHandler(), fd.ErrHandler)
}
2 changes: 1 addition & 1 deletion composition/file_content_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (loader *FileContentLoader) Load(fd *FetchDefinition) (Content, error, int)
WithField("duration", time.Since(parsingStart)).
Debug("content parsing")
f.Close()
return c, err,c.httpStatusCode
return c, err, c.httpStatusCode
}

c.reader = f
Expand Down
3 changes: 1 addition & 2 deletions composition/http_content_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewHttpContentLoader() *HttpContentLoader {
// TODO: Should we filter the headers, which we forward here, or is it correct to copy all of them?
func (loader *HttpContentLoader) Load(fd *FetchDefinition) (Content, error, int) {
client := &http.Client{Timeout: fd.Timeout}
statusCode:=502
statusCode := 502

var err error
request, err := http.NewRequest(fd.Method, fd.URL, fd.Body)
Expand All @@ -46,7 +46,6 @@ func (loader *HttpContentLoader) Load(fd *FetchDefinition) (Content, error, int)
statusCode = resp.StatusCode
}


logging.Call(request, resp, start, err)
if err != nil {
return nil, err, statusCode
Expand Down
5 changes: 1 addition & 4 deletions composition/http_content_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func Test_HttpContentLoader_Pass_404(t *testing.T) {
w.Write([]byte("{}"))
}))


defer server.Close()

loader := &HttpContentLoader{}
Expand All @@ -169,8 +168,6 @@ func Test_HttpContentLoader_Pass_404(t *testing.T) {
a.Equal(404, status)
}



func Test_HttpContentLoader_LoadError500(t *testing.T) {
a := assert.New(t)

Expand All @@ -184,7 +181,7 @@ func Test_HttpContentLoader_LoadError500(t *testing.T) {
a.Error(err)
a.Nil(c)
a.Contains(err.Error(), "http 500")
assert.True(t, statusCode==500)
assert.True(t, statusCode == 500)
}

func Test_HttpContentLoader_LoadErrorNetwork(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion composition/interface_mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package composition

import (
gomock "github.com/golang/mock/gomock"

io "io"
http "net/http"
)
Expand Down
2 changes: 1 addition & 1 deletion composition_example/example_ui_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import (
gorilla "github.com/gorilla/handlers"
"github.com/tarent/lib-compose/composition"
"net/http"
"os"
"github.com/tarent/lib-compose/composition"
)

func main() {
Expand Down

0 comments on commit ee1aad4

Please sign in to comment.