wisski-cloud-distillery/env/server.go
Tom Wiesing 4b357476a3
Add 'dis' component
This commit adds a new 'dis' component to the distillery that serves a
list of all known instances for the moment.
2022-09-09 17:10:24 +02:00

31 lines
555 B
Go

package env
import (
"io"
"net/http"
)
// Server represents a server for this distillery
type Server struct {
dis *Distillery
}
func (dis *Distillery) Server() *Server {
return &Server{
dis: dis,
}
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
instances, err := s.dis.AllInstances()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
io.WriteString(w, "Something went wrong")
return
}
w.WriteHeader(http.StatusOK)
for _, instance := range instances {
io.WriteString(w, instance.Slug+"\n")
}
}