mirror of
https://github.com/Lomanic/fuz-spaceapi
synced 2024-11-22 00:07:30 +00:00
Make app configurable via SPACEAPI env variable
This commit is contained in:
parent
7d44134f12
commit
2369064908
@ -3,3 +3,9 @@
|
|||||||
Simple project in Go retrieving opening status from [presence button API](https://wiki.fuz.re/doku.php?id=projets:fuz:presence_button) and serving JSON according to [SpaceAPI specs](https://spaceapi.io/docs/).
|
Simple project in Go retrieving opening status from [presence button API](https://wiki.fuz.re/doku.php?id=projets:fuz:presence_button) and serving JSON according to [SpaceAPI specs](https://spaceapi.io/docs/).
|
||||||
|
|
||||||
Read about it on [Fuz wiki](https://wiki.fuz.re/doku.php?id=projets:fuz:spaceapi).
|
Read about it on [Fuz wiki](https://wiki.fuz.re/doku.php?id=projets:fuz:spaceapi).
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
The app gets its configuration from these environment variables:
|
||||||
|
* `PRESENCEAPI`: URL where the app should get the space opening status (e.g. `PRESENCEAPI=https://presence.fuz.re/api`)
|
||||||
|
* `SPACEAPI`: JSON string, static information to be served on the endpoint (e.g. `SPACEAPI='{"api":"0.13","space":"FUZ","logo":"https://fuz.re/WWW.FUZ.RE_fichiers/5c02b2a84373a.png","url":"https://fuz.re/","location":{"address":"11-15 rue dela Réunion, Paris 75020, FRANCE","lon":2.40308,"lat":48.85343},"contact":{"email":"","irc":"","ml":"fuz@fuz.re","twitter":"@fuz_re","matrix":"https://matrix.to/#/#fuz_general:matrix.fuz.re"},"issue_report_channels":["ml","twitter"],"state":{"icon":{"open":"https://presence.fuz.re/img","closed":"https://presence.fuz.re/img"},"message":"open under conditions: https://wiki.fuz.re/doku.php?id=map"},"projects":["https://wiki.fuz.re/doku.php?id=projets:fuz:start"]}'`)
|
||||||
|
94
main.go
94
main.go
@ -13,40 +13,37 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
PORT string
|
PORT string
|
||||||
PRESENCEAPI string
|
PRESENCEAPI string
|
||||||
|
SPACEAPI string
|
||||||
}
|
}
|
||||||
|
|
||||||
type SpaceAPI struct {
|
type SpaceAPI 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 struct {
|
||||||
Contact Contact `json:"contact"`
|
Address string `json:"address,omitempty"`
|
||||||
|
Lon float64 `json:"lon"`
|
||||||
|
Lat float64 `json:"lat"`
|
||||||
|
} `json:"location"`
|
||||||
|
Contact struct {
|
||||||
|
Email string `json:"email,omitempty"`
|
||||||
|
Irc string `json:"irc,omitempty"`
|
||||||
|
Ml string `json:"ml,omitempty"`
|
||||||
|
Twitter string `json:"twitter,omitempty"`
|
||||||
|
Matrix string `json:"matrix,omitempty"`
|
||||||
|
} `json:"contact"`
|
||||||
IssueReportChannels []string `json:"issue_report_channels"`
|
IssueReportChannels []string `json:"issue_report_channels"`
|
||||||
State State `json:"state"`
|
State struct {
|
||||||
Projects []string `json:"projects"`
|
Icon struct {
|
||||||
}
|
Open string `json:"open"`
|
||||||
type Location struct {
|
Closed string `json:"closed"`
|
||||||
Address string `json:"address"`
|
} `json:"icon,omitempty"`
|
||||||
Lon float64 `json:"lon"`
|
Open bool `json:"open"`
|
||||||
Lat float64 `json:"lat"`
|
Message string `json:"message,omitempty"`
|
||||||
}
|
LastChange int64 `json:"lastchange,omitempty"`
|
||||||
type Contact struct {
|
} `json:"state"`
|
||||||
Email string `json:"email"`
|
Projects []string `json:"projects,omitempty"`
|
||||||
IRC string `json:"irc"`
|
|
||||||
ML string `json:"ml"`
|
|
||||||
Twitter string `json:"twitter"`
|
|
||||||
Matrix string `json:"matrix"`
|
|
||||||
}
|
|
||||||
type Icon struct {
|
|
||||||
Open string `json:"open"`
|
|
||||||
Closed string `json:"closed"`
|
|
||||||
}
|
|
||||||
type State struct {
|
|
||||||
Icon Icon `json:"icon"`
|
|
||||||
Open bool `json:"open"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
LastChange int64 `json:"lastchange"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Status struct {
|
type Status struct {
|
||||||
@ -62,34 +59,7 @@ var (
|
|||||||
PORT: "8080",
|
PORT: "8080",
|
||||||
}
|
}
|
||||||
spaceAPI = SpaceAPI{
|
spaceAPI = SpaceAPI{
|
||||||
API: "0.13",
|
API: "0.13",
|
||||||
Space: "FUZ",
|
|
||||||
Logo: "https://fuz.re/WWW.FUZ.RE_fichiers/5c02b2a84373a.png",
|
|
||||||
URL: "https://fuz.re/",
|
|
||||||
Location: Location{
|
|
||||||
Address: "11-15 rue de la Réunion, Paris 75020, FRANCE",
|
|
||||||
Lat: 48.85343,
|
|
||||||
Lon: 2.40308,
|
|
||||||
},
|
|
||||||
Contact: Contact{
|
|
||||||
ML: "fuz@fuz.re",
|
|
||||||
Twitter: "@fuz_re",
|
|
||||||
Matrix: "https://matrix.to/#/#fuz_general:matrix.fuz.re",
|
|
||||||
},
|
|
||||||
IssueReportChannels: []string{
|
|
||||||
"ml",
|
|
||||||
"twitter",
|
|
||||||
},
|
|
||||||
State: State{
|
|
||||||
Icon: Icon{
|
|
||||||
Open: "https://presence.fuz.re/img",
|
|
||||||
Closed: "https://presence.fuz.re/img",
|
|
||||||
},
|
|
||||||
Message: "open under conditions: https://wiki.fuz.re/doku.php?id=map",
|
|
||||||
},
|
|
||||||
Projects: []string{
|
|
||||||
"https://wiki.fuz.re/doku.php?id=projets:fuz:start",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -102,6 +72,14 @@ func init() {
|
|||||||
if config.PRESENCEAPI == "" {
|
if config.PRESENCEAPI == "" {
|
||||||
panic("PRESENCEAPI is empty")
|
panic("PRESENCEAPI is empty")
|
||||||
}
|
}
|
||||||
|
config.SPACEAPI = os.Getenv("SPACEAPI")
|
||||||
|
if config.SPACEAPI == "" {
|
||||||
|
panic("SPACEAPI is empty")
|
||||||
|
}
|
||||||
|
err := json.Unmarshal([]byte(config.SPACEAPI), &spaceAPI)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("SPACEAPI is not valid JSON: %v", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
Loading…
Reference in New Issue
Block a user