gofmt
This commit is contained in:
parent
dc7db298bd
commit
89ae122fc3
9 changed files with 113 additions and 114 deletions
|
|
@ -44,4 +44,4 @@ func mapEventObject(event *ics.Event) Event {
|
||||||
eventData.WholeDayEvent = event.GetWholeDayEvent()
|
eventData.WholeDayEvent = event.GetWholeDayEvent()
|
||||||
|
|
||||||
return eventData
|
return eventData
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,4 @@ type ConfigFile struct {
|
||||||
SharedSecret string `yaml:"shared_secret,omitempty"`
|
SharedSecret string `yaml:"shared_secret,omitempty"`
|
||||||
MongoDbServer string `yaml:"mongodb_server,omitempty"`
|
MongoDbServer string `yaml:"mongodb_server,omitempty"`
|
||||||
MongoDbDatabase string `yaml:"mongodb_database,omitempty"`
|
MongoDbDatabase string `yaml:"mongodb_database,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,52 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"encoding/json"
|
"os"
|
||||||
"gopkg.in/yaml.v2"
|
"time"
|
||||||
"log"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var config = ConfigFile{}
|
var config = ConfigFile{}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data, _ := ioutil.ReadFile("config.yaml")
|
data, _ := ioutil.ReadFile("config.yaml")
|
||||||
err := yaml.Unmarshal(data, &config)
|
err := yaml.Unmarshal(data, &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Can't load config")
|
panic("Can't load config")
|
||||||
}
|
}
|
||||||
config.SharedSecret = os.Getenv("SHARED_SECRET")
|
config.SharedSecret = os.Getenv("SHARED_SECRET")
|
||||||
|
|
||||||
c := cron.New()
|
c := cron.New()
|
||||||
err = c.AddFunc("@hourly", func() {
|
err = c.AddFunc("@hourly", func() {
|
||||||
loadSpaceData()
|
loadSpaceData()
|
||||||
getCalendars()
|
getCalendars()
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Can't start cron %v", err)
|
log.Printf("Can't start cron %v", err)
|
||||||
} else {
|
} else {
|
||||||
c.Start()
|
c.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
router := NewRouter()
|
router := NewRouter()
|
||||||
http.Handle("/", router)
|
http.Handle("/", router)
|
||||||
log.Fatal(http.ListenAndServe(":8080", router))
|
log.Fatal(http.ListenAndServe(":8080", router))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getJson(url string, target interface{}) error {
|
func getJson(url string, target interface{}) error {
|
||||||
r, err := http.Get(url)
|
r, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer r.Body.Close()
|
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) {
|
func SpaceDataIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -108,7 +108,7 @@ func loadSpaceData() {
|
||||||
timestamp := time.Now().Unix()
|
timestamp := time.Now().Unix()
|
||||||
|
|
||||||
for _, spaceUrl := range spaceUrls {
|
for _, spaceUrl := range spaceUrls {
|
||||||
if spaceUrl.Validated && int64(spaceUrl.LastUpdated + 60) < timestamp {
|
if spaceUrl.Validated && int64(spaceUrl.LastUpdated+60) < timestamp {
|
||||||
spaceData := SpaceData{}
|
spaceData := SpaceData{}
|
||||||
err := getJson(spaceUrl.Url, &spaceData)
|
err := getJson(spaceUrl.Url, &spaceData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -125,8 +125,8 @@ func loadSpaceData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func refreshData(w http.ResponseWriter, r *http.Request) {
|
func refreshData(w http.ResponseWriter, r *http.Request) {
|
||||||
loadSpaceData()
|
loadSpaceData()
|
||||||
getCalendars()
|
getCalendars()
|
||||||
|
|
||||||
w.WriteHeader(204)
|
w.WriteHeader(204)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,20 @@ package main
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type Calendar struct {
|
type Calendar struct {
|
||||||
Space string
|
Space string
|
||||||
Events []Event
|
Events []Event
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Start time.Time `json:"start"`
|
Start time.Time `json:"start"`
|
||||||
ImportedId string `json:"importId"`
|
ImportedId string `json:"importId"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
Summary string `json:"summary"`
|
Summary string `json:"summary"`
|
||||||
Rrule string `json:"rrule"`
|
Rrule string `json:"rrule"`
|
||||||
Class string `json:"class"`
|
Class string `json:"class"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Sequence int `json:"sequence"`
|
Sequence int `json:"sequence"`
|
||||||
WholeDayEvent bool `json:"wholeDayEvent"`
|
WholeDayEvent bool `json:"wholeDayEvent"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,4 @@ func logError(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DataObject interface {
|
type DataObject interface {
|
||||||
|
|
@ -45,4 +45,4 @@ func createEntry(i interface{}, w http.ResponseWriter, r *http.Request) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewRouter() *mux.Router {
|
func NewRouter() *mux.Router {
|
||||||
|
|
@ -13,21 +13,21 @@ func NewRouter() *mux.Router {
|
||||||
handler = Logger(route.Handler, route.Name)
|
handler = Logger(route.Handler, route.Name)
|
||||||
|
|
||||||
router.
|
router.
|
||||||
Methods(route.Method).
|
Methods(route.Method).
|
||||||
Path(route.Pattern).
|
Path(route.Pattern).
|
||||||
Name(route.Name).
|
Name(route.Name).
|
||||||
Handler(handler)
|
Handler(handler)
|
||||||
|
|
||||||
router.
|
router.
|
||||||
Methods("OPTIONS").
|
Methods("OPTIONS").
|
||||||
Name("Options Handler").
|
Name("Options Handler").
|
||||||
Handler(http.HandlerFunc(optionsHandler))
|
Handler(http.HandlerFunc(optionsHandler))
|
||||||
}
|
}
|
||||||
|
|
||||||
router.
|
router.
|
||||||
Methods("OPTIONS").
|
Methods("OPTIONS").
|
||||||
Name("Options Handler").
|
Name("Options Handler").
|
||||||
Handler(http.HandlerFunc(optionsHandler))
|
Handler(http.HandlerFunc(optionsHandler))
|
||||||
|
|
||||||
router.NotFoundHandler = http.HandlerFunc(notFound)
|
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-Headers", "Content-Type")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE")
|
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE")
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ type Route struct {
|
||||||
Handler http.HandlerFunc
|
Handler http.HandlerFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type Routes []Route
|
type Routes []Route
|
||||||
|
|
||||||
var IndexRoutes = Routes{
|
var IndexRoutes = Routes{
|
||||||
|
|
@ -61,4 +60,4 @@ var IndexRoutes = Routes{
|
||||||
"/refresh",
|
"/refresh",
|
||||||
refreshData,
|
refreshData,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,71 +3,71 @@ package main
|
||||||
// non standard should start with ext_
|
// non standard should start with ext_
|
||||||
|
|
||||||
type Location struct {
|
type Location struct {
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
// non standard
|
// non standard
|
||||||
ExtFloor int `json:"ext_floor"`
|
ExtFloor int `json:"ext_floor"`
|
||||||
Lon float32 `json:"lon"`
|
Lon float32 `json:"lon"`
|
||||||
Lat float32 `json:"lat"`
|
Lat float32 `json:"lat"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SpaceFed struct {
|
type SpaceFed struct {
|
||||||
SpaceNet bool `json:"spacenet"`
|
SpaceNet bool `json:"spacenet"`
|
||||||
Spacesaml bool `json:"spacesaml"`
|
Spacesaml bool `json:"spacesaml"`
|
||||||
SpacePhone bool `json:"spacephone"`
|
SpacePhone bool `json:"spacephone"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stream struct {
|
type Stream struct {
|
||||||
M4 bool `json:"m4,omitempty"`
|
M4 bool `json:"m4,omitempty"`
|
||||||
MJPEG bool `json:"mjpeg,omitempty"`
|
MJPEG bool `json:"mjpeg,omitempty"`
|
||||||
UStream bool `json:"ustream,omitempty"`
|
UStream bool `json:"ustream,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
Open bool `json:"open"`
|
Open bool `json:"open"`
|
||||||
Lastchange float64 `json:"lastchange,omitempty"`
|
Lastchange float64 `json:"lastchange,omitempty"`
|
||||||
TriggerPerson string `json:"trigger_person,omitempty"`
|
TriggerPerson string `json:"trigger_person,omitempty"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
Icon struct {
|
Icon struct {
|
||||||
Open string `json:"open"`
|
Open string `json:"open"`
|
||||||
Closed string `json:"closed"`
|
Closed string `json:"closed"`
|
||||||
} `json:"icon,omitempty"`
|
} `json:"icon,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Contact struct {
|
type Contact struct {
|
||||||
Twitter string `json:"twitter"`
|
Twitter string `json:"twitter"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
Irc string `json:"irc"`
|
Irc string `json:"irc"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Ml string `json:"ml"`
|
Ml string `json:"ml"`
|
||||||
IssueMail string `json:"issue_mail"`
|
IssueMail string `json:"issue_mail"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Feeds struct {
|
type Feeds struct {
|
||||||
Blog Feed `json:"blog"`
|
Blog Feed `json:"blog"`
|
||||||
Wiki Feed `json:"wiki"`
|
Wiki Feed `json:"wiki"`
|
||||||
Calendar Feed `json:"calendar"`
|
Calendar Feed `json:"calendar"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// main struct
|
// main struct
|
||||||
|
|
||||||
type SpaceData struct {
|
type SpaceData struct {
|
||||||
Api string `json:"api"`
|
Api string `json:"api"`
|
||||||
Space string `json:"space"`
|
Space string `json:"space"`
|
||||||
Logo string `json:"logo"`
|
Logo string `json:"logo"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url"`
|
||||||
Location Location `json:"location"`
|
Location Location `json:"location"`
|
||||||
SpaceFed SpaceFed `json:"spacefed,omitempty"`
|
SpaceFed SpaceFed `json:"spacefed,omitempty"`
|
||||||
Cam []string `json:"cam,omitempty"`
|
Cam []string `json:"cam,omitempty"`
|
||||||
Stream *Stream `json:"stream,omitempty"`
|
Stream *Stream `json:"stream,omitempty"`
|
||||||
State State `json:"state"`
|
State State `json:"state"`
|
||||||
// missing: `json:"events,omitempty"`
|
// missing: `json:"events,omitempty"`
|
||||||
Contact *Contact `json:"contact,omitempty"`
|
Contact *Contact `json:"contact,omitempty"`
|
||||||
IssueReportChannels []string `json:"issue_report_channels"`
|
IssueReportChannels []string `json:"issue_report_channels"`
|
||||||
// missing: `json:"sensors,omitempty"`
|
// missing: `json:"sensors,omitempty"`
|
||||||
Feeds Feeds `json:"feeds,omitempty"`
|
Feeds Feeds `json:"feeds,omitempty"`
|
||||||
// missing: `json:"cache,omitempty"`
|
// missing: `json:"cache,omitempty"`
|
||||||
Projects []string `json:"projects,omitempty"`
|
Projects []string `json:"projects,omitempty"`
|
||||||
// missing: `json:"radio_show,omitempty"`
|
// missing: `json:"radio_show,omitempty"`
|
||||||
// not in spaceapi.io/docs
|
// not in spaceapi.io/docs
|
||||||
Ext_ccc string `json:"ext_ccc"`
|
Ext_ccc string `json:"ext_ccc"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue