From 89ae122fc39e49f77c88914fe652d186de6d4630 Mon Sep 17 00:00:00 2001 From: genofire Date: Sat, 28 Dec 2019 17:44:54 +0100 Subject: [PATCH] gofmt --- backend/calendar.go | 2 +- backend/configFile.go | 2 +- backend/eva-backend.go | 72 ++++++++++++++++----------------- backend/event.go | 26 ++++++------ backend/logger.go | 2 +- backend/response.go | 4 +- backend/router.go | 24 +++++------ backend/routes.go | 3 +- backend/spacedata.go | 90 +++++++++++++++++++++--------------------- 9 files changed, 112 insertions(+), 113 deletions(-) diff --git a/backend/calendar.go b/backend/calendar.go index 06882f0..c6966e4 100644 --- a/backend/calendar.go +++ b/backend/calendar.go @@ -44,4 +44,4 @@ func mapEventObject(event *ics.Event) Event { eventData.WholeDayEvent = event.GetWholeDayEvent() return eventData -} \ No newline at end of file +} diff --git a/backend/configFile.go b/backend/configFile.go index 16e587c..00df543 100644 --- a/backend/configFile.go +++ b/backend/configFile.go @@ -4,4 +4,4 @@ type ConfigFile struct { SharedSecret string `yaml:"shared_secret,omitempty"` MongoDbServer string `yaml:"mongodb_server,omitempty"` MongoDbDatabase string `yaml:"mongodb_database,omitempty"` -} \ No newline at end of file +} diff --git a/backend/eva-backend.go b/backend/eva-backend.go index 18a2013..476b064 100644 --- a/backend/eva-backend.go +++ b/backend/eva-backend.go @@ -1,52 +1,52 @@ package main import ( + "encoding/json" "github.com/gofrs/uuid" + "github.com/gorilla/mux" "github.com/robfig/cron" + "gopkg.in/yaml.v2" + "io/ioutil" + "log" "net/http" - "encoding/json" - "gopkg.in/yaml.v2" - "log" - "io/ioutil" - "os" - "time" - "github.com/gorilla/mux" + "os" + "time" ) var config = ConfigFile{} func main() { - data, _ := ioutil.ReadFile("config.yaml") - err := yaml.Unmarshal(data, &config) - if err != nil { - panic("Can't load config") - } - config.SharedSecret = os.Getenv("SHARED_SECRET") + data, _ := ioutil.ReadFile("config.yaml") + err := yaml.Unmarshal(data, &config) + if err != nil { + panic("Can't load config") + } + config.SharedSecret = os.Getenv("SHARED_SECRET") - c := cron.New() - err = c.AddFunc("@hourly", func() { - loadSpaceData() - getCalendars() - }) - if err != nil { - log.Printf("Can't start cron %v", err) - } else { - c.Start() - } + c := cron.New() + err = c.AddFunc("@hourly", func() { + loadSpaceData() + getCalendars() + }) + if err != nil { + log.Printf("Can't start cron %v", err) + } else { + c.Start() + } - router := NewRouter() - http.Handle("/", router) - log.Fatal(http.ListenAndServe(":8080", router)) + router := NewRouter() + http.Handle("/", router) + log.Fatal(http.ListenAndServe(":8080", router)) } func getJson(url string, target interface{}) error { - r, err := http.Get(url) - if err != nil { - return err - } - defer r.Body.Close() + r, err := http.Get(url) + if err != nil { + return err + } + defer r.Body.Close() - return json.NewDecoder(r.Body).Decode(target) + return json.NewDecoder(r.Body).Decode(target) } func SpaceDataIndex(w http.ResponseWriter, r *http.Request) { @@ -108,7 +108,7 @@ func loadSpaceData() { timestamp := time.Now().Unix() for _, spaceUrl := range spaceUrls { - if spaceUrl.Validated && int64(spaceUrl.LastUpdated + 60) < timestamp { + if spaceUrl.Validated && int64(spaceUrl.LastUpdated+60) < timestamp { spaceData := SpaceData{} err := getJson(spaceUrl.Url, &spaceData) if err != nil { @@ -125,8 +125,8 @@ func loadSpaceData() { } func refreshData(w http.ResponseWriter, r *http.Request) { - loadSpaceData() - getCalendars() + loadSpaceData() + getCalendars() - w.WriteHeader(204) + w.WriteHeader(204) } diff --git a/backend/event.go b/backend/event.go index 5af2209..34cc760 100644 --- a/backend/event.go +++ b/backend/event.go @@ -3,20 +3,20 @@ package main import "time" type Calendar struct { - Space string - Events []Event + Space string + Events []Event } type Event struct { Start time.Time `json:"start"` - ImportedId string `json:"importId"` - Status string `json:"status"` - Description string `json:"description"` - Location string `json:"location"` - Summary string `json:"summary"` - Rrule string `json:"rrule"` - Class string `json:"class"` - Url string `json:"url"` - Sequence int `json:"sequence"` - WholeDayEvent bool `json:"wholeDayEvent"` -} \ No newline at end of file + ImportedId string `json:"importId"` + Status string `json:"status"` + Description string `json:"description"` + Location string `json:"location"` + Summary string `json:"summary"` + Rrule string `json:"rrule"` + Class string `json:"class"` + Url string `json:"url"` + Sequence int `json:"sequence"` + WholeDayEvent bool `json:"wholeDayEvent"` +} diff --git a/backend/logger.go b/backend/logger.go index 94dfecf..3a24c04 100644 --- a/backend/logger.go +++ b/backend/logger.go @@ -26,4 +26,4 @@ func logError(err error) { if err != nil { log.Fatal(err) } -} \ No newline at end of file +} diff --git a/backend/response.go b/backend/response.go index 2bf1825..f8ea36b 100644 --- a/backend/response.go +++ b/backend/response.go @@ -1,9 +1,9 @@ package main import ( - "net/http" "encoding/json" "fmt" + "net/http" ) type DataObject interface { @@ -45,4 +45,4 @@ func createEntry(i interface{}, w http.ResponseWriter, r *http.Request) { panic(err) } } -} \ No newline at end of file +} diff --git a/backend/router.go b/backend/router.go index 125d101..8d46c39 100644 --- a/backend/router.go +++ b/backend/router.go @@ -1,9 +1,9 @@ package main import ( - "net/http" "github.com/gorilla/mux" "log" + "net/http" ) func NewRouter() *mux.Router { @@ -13,21 +13,21 @@ func NewRouter() *mux.Router { handler = Logger(route.Handler, route.Name) router. - Methods(route.Method). - Path(route.Pattern). - Name(route.Name). - Handler(handler) + Methods(route.Method). + Path(route.Pattern). + Name(route.Name). + Handler(handler) router. - Methods("OPTIONS"). - Name("Options Handler"). - Handler(http.HandlerFunc(optionsHandler)) + Methods("OPTIONS"). + Name("Options Handler"). + Handler(http.HandlerFunc(optionsHandler)) } router. - Methods("OPTIONS"). - Name("Options Handler"). - Handler(http.HandlerFunc(optionsHandler)) + Methods("OPTIONS"). + Name("Options Handler"). + Handler(http.HandlerFunc(optionsHandler)) router.NotFoundHandler = http.HandlerFunc(notFound) @@ -48,4 +48,4 @@ func optionsHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Headers", "Content-Type") w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE") w.WriteHeader(200) -} \ No newline at end of file +} diff --git a/backend/routes.go b/backend/routes.go index 7fa3972..44d0b5e 100644 --- a/backend/routes.go +++ b/backend/routes.go @@ -9,7 +9,6 @@ type Route struct { Handler http.HandlerFunc } - type Routes []Route var IndexRoutes = Routes{ @@ -61,4 +60,4 @@ var IndexRoutes = Routes{ "/refresh", refreshData, }, -} \ No newline at end of file +} diff --git a/backend/spacedata.go b/backend/spacedata.go index c2530cd..9a977eb 100644 --- a/backend/spacedata.go +++ b/backend/spacedata.go @@ -3,71 +3,71 @@ package main // non standard should start with ext_ type Location struct { - Address string `json:"address"` - // non standard - ExtFloor int `json:"ext_floor"` - Lon float32 `json:"lon"` - Lat float32 `json:"lat"` + Address string `json:"address"` + // non standard + ExtFloor int `json:"ext_floor"` + Lon float32 `json:"lon"` + Lat float32 `json:"lat"` } type SpaceFed struct { - SpaceNet bool `json:"spacenet"` - Spacesaml bool `json:"spacesaml"` - SpacePhone bool `json:"spacephone"` + SpaceNet bool `json:"spacenet"` + Spacesaml bool `json:"spacesaml"` + SpacePhone bool `json:"spacephone"` } type Stream struct { M4 bool `json:"m4,omitempty"` MJPEG bool `json:"mjpeg,omitempty"` - UStream bool `json:"ustream,omitempty"` + UStream bool `json:"ustream,omitempty"` } type State struct { - Open bool `json:"open"` - Lastchange float64 `json:"lastchange,omitempty"` - TriggerPerson string `json:"trigger_person,omitempty"` - Message string `json:"message,omitempty"` - Icon struct { - Open string `json:"open"` - Closed string `json:"closed"` - } `json:"icon,omitempty"` + Open bool `json:"open"` + Lastchange float64 `json:"lastchange,omitempty"` + TriggerPerson string `json:"trigger_person,omitempty"` + Message string `json:"message,omitempty"` + Icon struct { + Open string `json:"open"` + Closed string `json:"closed"` + } `json:"icon,omitempty"` } type Contact struct { - Twitter string `json:"twitter"` - Phone string `json:"phone"` - Irc string `json:"irc"` - Email string `json:"email"` - Ml string `json:"ml"` - IssueMail string `json:"issue_mail"` + Twitter string `json:"twitter"` + Phone string `json:"phone"` + Irc string `json:"irc"` + Email string `json:"email"` + Ml string `json:"ml"` + IssueMail string `json:"issue_mail"` } type Feeds struct { - Blog Feed `json:"blog"` - Wiki Feed `json:"wiki"` - Calendar Feed `json:"calendar"` + Blog Feed `json:"blog"` + Wiki Feed `json:"wiki"` + Calendar Feed `json:"calendar"` } // main struct type SpaceData struct { - Api string `json:"api"` - Space string `json:"space"` - Logo string `json:"logo"` - Url string `json:"url"` - Location Location `json:"location"` - SpaceFed SpaceFed `json:"spacefed,omitempty"` - Cam []string `json:"cam,omitempty"` - Stream *Stream `json:"stream,omitempty"` - State State `json:"state"` - // missing: `json:"events,omitempty"` - Contact *Contact `json:"contact,omitempty"` - IssueReportChannels []string `json:"issue_report_channels"` - // missing: `json:"sensors,omitempty"` - Feeds Feeds `json:"feeds,omitempty"` - // missing: `json:"cache,omitempty"` - Projects []string `json:"projects,omitempty"` - // missing: `json:"radio_show,omitempty"` - // not in spaceapi.io/docs - Ext_ccc string `json:"ext_ccc"` + Api string `json:"api"` + Space string `json:"space"` + Logo string `json:"logo"` + Url string `json:"url"` + Location Location `json:"location"` + SpaceFed SpaceFed `json:"spacefed,omitempty"` + Cam []string `json:"cam,omitempty"` + Stream *Stream `json:"stream,omitempty"` + State State `json:"state"` + // missing: `json:"events,omitempty"` + Contact *Contact `json:"contact,omitempty"` + IssueReportChannels []string `json:"issue_report_channels"` + // missing: `json:"sensors,omitempty"` + Feeds Feeds `json:"feeds,omitempty"` + // missing: `json:"cache,omitempty"` + Projects []string `json:"projects,omitempty"` + // missing: `json:"radio_show,omitempty"` + // not in spaceapi.io/docs + Ext_ccc string `json:"ext_ccc"` }