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
43
cmd/dis_server.go
Normal file
43
cmd/dis_server.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/core"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
||||
// DisServer is the 'dis_server' command
|
||||
var DisServer wisski_distillery.Command = disServer{}
|
||||
|
||||
type disServer struct {
|
||||
Prefix string `short:"p" long:"prefix" description:"prefix to listen under"`
|
||||
Bind string `short:"b" long:"bind" description:"address to listen on" default:"127.0.0.1:8888"`
|
||||
}
|
||||
|
||||
func (disServer) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: core.Requirements{
|
||||
NeedsDistillery: true,
|
||||
},
|
||||
Command: "dis_server",
|
||||
Description: "Starts a server with information about this distillery",
|
||||
}
|
||||
}
|
||||
|
||||
var errServerListen = exit.Error{
|
||||
ExitCode: exit.ExitGeneric,
|
||||
Message: "Unable to listen",
|
||||
}
|
||||
|
||||
func (s disServer) Run(context wisski_distillery.Context) error {
|
||||
server := context.Environment.Server()
|
||||
|
||||
context.Printf("Listening on %s\n", s.Bind)
|
||||
err := http.ListenAndServe(s.Bind, http.StripPrefix(s.Prefix, server))
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errServerListen.Wrap(err)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue