mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2026-05-06 16:10:28 -05:00
34 lines
990 B
Go
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
|
|
}
|
|
}
|