okospaceapi/cmd/server.go

47 lines
928 B
Go
Raw Normal View History

2023-09-28 10:13:41 +02:00
package main
import (
"net/http"
"oko-spaceapi/pkg/spaceapi"
)
//go:generate ../generate-spaceapi-types.sh
func main() {
definition := spaceapi.Root{
// TODO: Fill up with stuff
ApiCompatibility: []string{"14"},
Links: []*spaceapi.LinksItems{
{
Description: "Out main website",
Name: "website",
Url: "https://okoyono.de",
},
},
Space: "økoyono",
Url: "https://okoyono.de/",
Contact: &spaceapi.Contact{
Email: "contact@okoyono.de",
},
Location: &spaceapi.Location{
Address: "",
},
}
json, err := definition.MarshalJSON()
if err != nil {
panic(err)
}
err = http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, err := w.Write(json)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}))
if err != nil {
panic(err)
}
}