Merge all the server components
This commit is contained in:
parent
85b5603d9d
commit
f5f2ac1a03
25 changed files with 365 additions and 352 deletions
46
cmd/server.go
Normal file
46
cmd/server.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/core"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
||||
// Server is the 'server' command
|
||||
var Server wisski_distillery.Command = server{}
|
||||
|
||||
type server 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 (s server) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: core.Requirements{
|
||||
NeedsDistillery: true,
|
||||
},
|
||||
Command: "server",
|
||||
Description: "Starts a server with information about this distillery",
|
||||
}
|
||||
}
|
||||
|
||||
var errServerListen = exit.Error{
|
||||
ExitCode: exit.ExitGeneric,
|
||||
Message: "Unable to listen",
|
||||
}
|
||||
|
||||
func (s server) Run(context wisski_distillery.Context) error {
|
||||
handler, err := context.Environment.Dis().Server(context.IOStream)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
context.Printf("Listening on %s\n", s.Bind)
|
||||
err = http.ListenAndServe(s.Bind, http.StripPrefix(s.Prefix, handler))
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errServerListen.Wrap(err)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue