Skip to content

Commit

Permalink
Apply go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurie Clark-Michalek committed Jun 19, 2015
1 parent 4eebe32 commit 2e80af3
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 79 deletions.
9 changes: 4 additions & 5 deletions api/event_subscription.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package api


import (
"encoding/json"
"github.com/QubitProducts/bamboo/configuration"
eb "github.com/QubitProducts/bamboo/services/event_bus"
"net/http"
"io"
"log"
"encoding/json"
"io/ioutil"
"log"
"net/http"
)

type EventSubscriptionAPI struct {
Conf *configuration.Configuration
Conf *configuration.Configuration
EventBus *eb.EventBus
}

Expand Down
2 changes: 1 addition & 1 deletion api/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type StateAPI struct {
}

func (state *StateAPI) Get(w http.ResponseWriter, r *http.Request) {
templateData, _ := haproxy.GetTemplateData(state.Config, state.Zookeeper)
templateData, _ := haproxy.GetTemplateData(state.Config, state.Zookeeper)
payload, _ := json.Marshal(templateData)
io.WriteString(w, string(payload))
}
2 changes: 1 addition & 1 deletion api/status.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package api

import(
import (
"io"
"net/http"
)
Expand Down
20 changes: 10 additions & 10 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ func setValueFromEnv(field *string, envVar string) {
}

func setBoolValueFromEnv(field *bool, envVar string) {
env := os.Getenv(envVar)
if len(env) > 0 {
log.Printf("Using environment override %s=%t", envVar, env)
x, err := strconv.ParseBool(env)
if err != nil {
log.Printf("Error converting boolean value: %s\n", err)
env := os.Getenv(envVar)
if len(env) > 0 {
log.Printf("Using environment override %s=%t", envVar, env)
x, err := strconv.ParseBool(env)
if err != nil {
log.Printf("Error converting boolean value: %s\n", err)
}
*field = x
} else {
log.Printf("Environment variable not set: %s", envVar)
}
*field = x
} else {
log.Printf("Environment variable not set: %s", envVar)
}
}
4 changes: 2 additions & 2 deletions configuration/zookeeper.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package configuration

import (
"time"
"strings"
"time"
)

/*
Expand All @@ -12,7 +12,7 @@ type Zookeeper struct {
// comma separated host:port connection strings set
Host string
// zookeeper path
Path string
Path string
// Delay n seconds to report change event
ReportingDelay int64

Expand Down
4 changes: 2 additions & 2 deletions services/event_bus/event_bus.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package event_bus

import (
"log"
"reflect"
"sync"
"log"
)

type EventBus struct {
Expand Down Expand Up @@ -50,7 +50,7 @@ func (ebus *EventBus) Register(fn interface{}, forTypes ...interface{}) {
/**
* Publish an event to the EventBus
*/
func (ebus *EventBus) Publish(event interface {}) error {
func (ebus *EventBus) Publish(event interface{}) error {
ebus.lock.RLock()
defer ebus.lock.RUnlock()

Expand Down
6 changes: 3 additions & 3 deletions services/event_bus/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ func handleHAPUpdate(conf *configuration.Configuration, conn *zk.Conn) bool {
}

templateData, err := haproxy.GetTemplateData(conf, conn)

if err != nil {
log.Printf("Not updating haproxy because we failed to retrieve template data: \n %s\n", err)
return false
log.Printf("Not updating haproxy because we failed to retrieve template data: \n %s\n", err)
return false
}

newContent, err := template.RenderTemplate(conf.HAProxy.TemplatePath, string(templateContent), templateData)
Expand Down
8 changes: 4 additions & 4 deletions services/haproxy/haproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func GetTemplateData(config *conf.Configuration, conn *zk.Conn) (interface{}, er
apps, err := marathon.FetchApps(config.Marathon)

if err != nil {
return nil, err
}
return nil, err
}

services, err := service.All(conn, config.Bamboo.Zookeeper)

if err != nil {
return nil, err
}
return nil, err
}

return templateData{apps, services}, nil
}
76 changes: 38 additions & 38 deletions services/marathon/marathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ type MarathonApps struct {

type MarathonApp struct {
Id string `json:id`
HealthChecks []HealthCheck `json:healthChecks`
HealthChecks []HealthCheck `json:healthChecks`
Ports []int `json:ports`
Env map[string]string `json:env`
}

type HealthCheck struct {
Path string `json:path`
Path string `json:path`
Protocol string `json:protocol`
}

Expand All @@ -91,28 +91,28 @@ func fetchMarathonApps(endpoint string) (map[string]MarathonApp, error) {

if err != nil {
return nil, err
} else {
defer response.Body.Close()
var appResponse MarathonApps
}

contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}
defer response.Body.Close()
var appResponse MarathonApps

err = json.Unmarshal(contents, &appResponse)
if err != nil {
return nil, err
}
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, err
}

dataById := map[string]MarathonApp{}
err = json.Unmarshal(contents, &appResponse)
if err != nil {
return nil, err
}

for _, appConfig := range appResponse.Apps {
dataById[appConfig.Id] = appConfig
}
dataById := map[string]MarathonApp{}

return dataById, nil
for _, appConfig := range appResponse.Apps {
dataById[appConfig.Id] = appConfig
}

return dataById, nil
}

func fetchTasks(endpoint string) (map[string][]MarathonTask, error) {
Expand All @@ -125,31 +125,31 @@ func fetchTasks(endpoint string) (map[string][]MarathonTask, error) {

if err != nil {
return nil, err
} else {
contents, err := ioutil.ReadAll(response.Body)
defer response.Body.Close()
if err != nil {
return nil, err
}
}

err = json.Unmarshal(contents, &tasks)
if err != nil {
return nil, err
}
contents, err := ioutil.ReadAll(response.Body)
defer response.Body.Close()
if err != nil {
return nil, err
}

err = json.Unmarshal(contents, &tasks)
if err != nil {
return nil, err
}

taskList := tasks.Tasks
sort.Sort(taskList)
taskList := tasks.Tasks
sort.Sort(taskList)

tasksById := map[string][]MarathonTask{}
for _, task := range taskList {
if tasksById[task.AppId] == nil {
tasksById[task.AppId] = []MarathonTask{}
}
tasksById[task.AppId] = append(tasksById[task.AppId], task)
tasksById := map[string][]MarathonTask{}
for _, task := range taskList {
if tasksById[task.AppId] == nil {
tasksById[task.AppId] = []MarathonTask{}
}

return tasksById, nil
tasksById[task.AppId] = append(tasksById[task.AppId], task)
}

return tasksById, nil
}

func createApps(tasksById map[string][]MarathonTask, marathonApps map[string]MarathonApp) AppList {
Expand Down
4 changes: 2 additions & 2 deletions services/service/service.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package service

import (
"net/url"
"strings"
"github.com/QubitProducts/bamboo/Godeps/_workspace/src/github.com/samuel/go-zookeeper/zk"
conf "github.com/QubitProducts/bamboo/configuration"
"net/url"
"strings"
)

type Service struct {
Expand Down
19 changes: 9 additions & 10 deletions services/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package template

import (
"bytes"
"text/template"
"github.com/QubitProducts/bamboo/services/service"
"strings"
"text/template"
)

func hasKey(data map[string]service.Service, appId string) bool {
Expand All @@ -21,15 +21,15 @@ func getService(data map[string]service.Service, appId string) service.Service {
Returns string content of a rendered template
*/
func RenderTemplate(templateName string, templateContent string, data interface{}) (string, error) {
funcMap := template.FuncMap{
"hasKey": hasKey,
funcMap := template.FuncMap{
"hasKey": hasKey,
"getService": getService,
"Split": strings.Split,
"Contains":strings.Contains,
"Join": strings.Join,
"Replace": strings.Replace,
"ToUpper": strings.ToUpper,
"ToLower": strings.ToLower}
"Split": strings.Split,
"Contains": strings.Contains,
"Join": strings.Join,
"Replace": strings.Replace,
"ToUpper": strings.ToUpper,
"ToLower": strings.ToLower}

tpl := template.Must(template.New(templateName).Funcs(funcMap).Parse(templateContent))

Expand All @@ -42,4 +42,3 @@ func RenderTemplate(templateName string, templateContent string, data interface{

return strBuffer.String(), nil
}

2 changes: 1 addition & 1 deletion services/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ func TestTemplateToLowerFunction(t *testing.T) {
So(content, ShouldEqual, "example.com")
})
})
}
}

0 comments on commit 2e80af3

Please sign in to comment.