Skip to content

Commit

Permalink
- fixes after golint run
Browse files Browse the repository at this point in the history
  • Loading branch information
spolnik committed Oct 2, 2018
1 parent a14a03e commit 4fc5a78
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func downloadProblems() {
log.Printf("[INFO] problems loaded, count = %d", len(problems))
}

func loadProblems(problemsJson io.Reader) error {
jsonParser := json.NewDecoder(problemsJson)
func loadProblems(problemsJSON io.Reader) error {
jsonParser := json.NewDecoder(problemsJSON)

if err := jsonParser.Decode(&problems); err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http"
)

func SetupRouter() *gin.Engine {
func setupRouter() *gin.Engine {
router := gin.Default()

router.GET("health", api.HealthCheck)
Expand All @@ -21,20 +21,20 @@ func SetupRouter() *gin.Engine {
}

var (
problemsUrl string
problemsURL string
port string
)

func init() {
flag.StringVar(&problemsUrl, "problems-url", "http://localhost:8080", "Problems store url")
flag.StringVar(&problemsURL, "problems-url", "http://localhost:8080", "Problems store url")
flag.StringVar(&port, "port", "8081", "Port to listen on")
flag.Parse()

log.SetFlags(log.LstdFlags)
}

func main() {
api.SetupProblems(problemsUrl, &http.Client{})
router := SetupRouter()
api.SetupProblems(problemsURL, &http.Client{})
router := setupRouter()
router.Run(":" + port)
}
34 changes: 17 additions & 17 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"testing"
)

type MockHttpClient struct {
problemJson string
type MockHTTPClient struct {
problemJSON string
}

func (m *MockHttpClient) Get(url string) (*http.Response, error) {
func (m *MockHTTPClient) Get(url string) (*http.Response, error) {
response := &http.Response{
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(m.problemJson))),
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(m.problemJSON))),
StatusCode: http.StatusOK,
}

Expand All @@ -39,10 +39,10 @@ public class Solution {
}`
)

httpClient := &MockHttpClient{problemJson: problemsJson}
api.SetupProblems(problemsUrl, httpClient)
httpClient := &MockHTTPClient{problemJSON: problemsJSON}
api.SetupProblems(problemsURL, httpClient)

router := SetupRouter()
router := setupRouter()

w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/api/v1/code/java/fib", nil)
Expand All @@ -69,10 +69,10 @@ public class Solution {
}`
)

httpClient := &MockHttpClient{problemJson: problemsJson}
api.SetupProblems(problemsUrl, httpClient)
httpClient := &MockHTTPClient{problemJSON: problemsJSON}
api.SetupProblems(problemsURL, httpClient)

router := SetupRouter()
router := setupRouter()

w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/api/v1/code/java/2-sum", nil)
Expand Down Expand Up @@ -100,10 +100,10 @@ public class Solution {
}`
)

httpClient := &MockHttpClient{problemJson: problemsJson}
api.SetupProblems(problemsUrl, httpClient)
httpClient := &MockHTTPClient{problemJSON: problemsJSON}
api.SetupProblems(problemsURL, httpClient)

router := SetupRouter()
router := setupRouter()

w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/api/v1/code/java/word-ladder", nil)
Expand All @@ -130,10 +130,10 @@ public class Solution {
}`
)

httpClient := &MockHttpClient{problemJson: problemsJson}
api.SetupProblems(problemsUrl, httpClient)
httpClient := &MockHTTPClient{problemJSON: problemsJSON}
api.SetupProblems(problemsURL, httpClient)

router := SetupRouter()
router := setupRouter()

w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/api/v1/code/java/insert-range", nil)
Expand All @@ -143,7 +143,7 @@ public class Solution {
assert.Equal(t, javaSourceCode, w.Body.String())
}

const problemsJson = `[{
const problemsJSON = `[{
"id": "fib",
"func": {
"name": "fib",
Expand Down

0 comments on commit 4fc5a78

Please sign in to comment.