Files
mantrae/internal/api/handler/utilities.go
T
2025-02-25 13:53:12 +01:00

34 lines
990 B
Go

package handler
import (
"encoding/json"
"net/http"
"github.com/MizuchiLabs/mantrae/internal/util"
"github.com/MizuchiLabs/mantrae/pkg/build"
)
// GetVersion returns the current version of Mantrae as a plain text response
func GetVersion(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
data := map[string]string{"version": build.Version}
if err := json.NewEncoder(w).Encode(data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
// GetPublicIP attempts to resolve the public IP address of the current machine
func GetPublicIP(w http.ResponseWriter, r *http.Request) {
machineIPs, err := util.GetPublicIPsCached()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(machineIPs); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}