root endpoint and startup logs

This commit is contained in:
TaiAurori 2022-06-22 20:47:00 -04:00
parent b03aa46c00
commit e7cc5f4ba7
3 changed files with 28 additions and 1 deletions

View file

@ -6,6 +6,19 @@ import (
"github.com/gorilla/mux"
)
func rootEndpoint(w http.ResponseWriter, r *http.Request) {
sendJSON(w, YggdrasilInfo{
Status: "OK",
RuntimeMode: "productionMode",
AppAuthor: "Tripwire Team",
AppDescription: "Custom Yggdrasil authentication server",
SpecVersion: "5.2.0",
AppName: "tripwire.yggdrasil",
ImplVersion: "5.2.0",
AppOwner: "Who knows?",
})
}
func authenticateEndpoint(w http.ResponseWriter, r *http.Request) {
var authPayload AuthPayload
err := unmarshalTo(r, &authPayload)
@ -140,7 +153,7 @@ func invalidateEndpoint(w http.ResponseWriter, r *http.Request) {
}
func registerEndpoints(r *mux.Router) {
r.HandleFunc("/", notFoundStub)
r.HandleFunc("/", rootEndpoint)
r.HandleFunc("/authenticate", authenticateEndpoint).Methods("POST")
r.HandleFunc("/refresh", refreshTokenEndpoint).Methods("POST")
r.HandleFunc("/signout", signoutEndpoint).Methods("POST")

View file

@ -19,8 +19,11 @@ func handleRequests() {
}
func main() {
log.Println("Tripwire initializing...")
initDB()
log.Println("Tripwire started.")
handleRequests()
defer DB.Close()

View file

@ -41,6 +41,17 @@ type UserCredentials struct {
Password string `json:"password"`
}
type YggdrasilInfo struct {
Status string `json:"Status"`
RuntimeMode string `json:"Runtime-Mode"`
AppAuthor string `json:"Application-Author"`
AppDescription string `json:"Application-Description"`
SpecVersion string `json:"Specification-Version"`
AppName string `json:"Application-Name"`
ImplVersion string `json:"Implementation-Version"`
AppOwner string `json:"Application-Owner"`
}
type NotFoundError struct{}
func (m *NotFoundError) Error() string {