Merge all the server components

This commit is contained in:
Tom Wiesing 2022-09-15 15:04:35 +02:00
parent 85b5603d9d
commit f5f2ac1a03
No known key found for this signature in database
25 changed files with 365 additions and 352 deletions

View file

@ -8,44 +8,22 @@ import (
"github.com/tkw1536/goprogram/exit"
)
// ResolverServer is the 'resolver_server' command
var ResolverServer wisski_distillery.Command = server{
Desc: wisski_distillery.Description{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "resolver_server",
Description: "Starts a global resolver server",
},
Server: func(context wisski_distillery.Context) (http.Handler, error) {
return context.Environment.Resolver().Server(context.IOStream)
},
}
// DisServer is the 'dis_server' command
var DisServer wisski_distillery.Command = server{
Desc: wisski_distillery.Description{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "dis_server",
Description: "Starts a server with information about this distillery",
},
Server: func(context wisski_distillery.Context) (http.Handler, error) {
return context.Environment.Server(), nil
},
}
// 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"`
Desc wisski_distillery.Description
Server func(context wisski_distillery.Context) (http.Handler, error)
}
func (s server) Description() wisski_distillery.Description {
return s.Desc
return wisski_distillery.Description{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "server",
Description: "Starts a server with information about this distillery",
}
}
var errServerListen = exit.Error{
@ -54,7 +32,7 @@ var errServerListen = exit.Error{
}
func (s server) Run(context wisski_distillery.Context) error {
handler, err := s.Server(context)
handler, err := context.Environment.Dis().Server(context.IOStream)
if err != nil {
return err
}

View file

@ -38,8 +38,8 @@ func (upc updateprefixconfig) Run(context wisski_distillery.Context) error {
return errPrefixUpdateFailed.WithMessageF(err)
}
resolver := dis.Resolver()
target := resolver.ConfigPath()
ddis := dis.Dis()
target := ddis.ResolverConfigPath()
// print the configuration
config, err := os.OpenFile(target, os.O_WRONLY, fs.ModePerm)
@ -70,7 +70,7 @@ func (upc updateprefixconfig) Run(context wisski_distillery.Context) error {
// and restart the resolver to apply the config!
logging.LogMessage(context.IOStream, "restarting resolver stack")
if err := resolver.Stack().Restart(context.IOStream); err != nil {
if err := ddis.Stack().Restart(context.IOStream); err != nil {
return errPrefixUpdateFailed.WithMessageF(err)
}

View file

@ -50,8 +50,7 @@ func init() {
wdcli.Register(cmd.Monday)
// servers
wdcli.Register(cmd.DisServer)
wdcli.Register(cmd.ResolverServer)
wdcli.Register(cmd.Server)
}
// an error when no arguments are provided.