Add 'dis' component
This commit adds a new 'dis' component to the distillery that serves a list of all known instances for the moment.
This commit is contained in:
parent
35bb95c5ca
commit
4b357476a3
43 changed files with 434 additions and 167 deletions
31
env/server.go
vendored
Normal file
31
env/server.go
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue