website/pkg/controller/version/version.go
Noah dd1e6c2918 Initial commit
* Initial codebase (lot of work!)
* Uses vanilla Go net/http and implements by hand: session cookies
  backed by Redis; log in/out; CSRF protection; email verification flow;
  initial database models (User table)
2022-08-09 22:32:19 -07:00

34 lines
711 B
Go

package version
import (
"encoding/json"
"net/http"
"git.kirsle.net/apps/gosocial/pkg/config"
)
// Response JSON schema.
type Response struct {
Version string `json:"version"`
Build string `json:"build"`
BuildDate string `json:"buildDate"`
}
// Create the controller.
func Create() http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
buf, err := json.Marshal(Response{
Version: config.RuntimeVersion,
Build: config.RuntimeBuild,
BuildDate: config.RuntimeBuildDate,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(buf)
})
}