-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.go
43 lines (35 loc) · 1.04 KB
/
serve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"context"
"os/signal"
"syscall"
"github.com/gdatasoftwareag/tftp/v2/pkg/handler"
"github.com/gdatasoftwareag/tftp/v2/pkg/secfs"
"github.com/gdatasoftwareag/tftp/v2/pkg/tftp"
"github.com/gdatasoftwareag/tftp/v2/pkg/udp"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
var (
serveCmd = &cobra.Command{
Use: "serve",
Short: "Run the tftp server",
RunE: serveTFTP,
}
)
func serveTFTP(_ *cobra.Command, _ []string) (err error) {
logger.Info("Creating TFTP Server",
zap.Any("config", cfg),
)
responseHandling := tftp.NewResponseHandling(logger)
responseHandling.RegisterHandler(handler.NewHealthCheckHandler())
responseHandling.RegisterHandler(handler.NewFSHandler(secfs.New(cfg.FSHandlerBaseDir), logger))
var srv tftp.Server
if srv, err = tftp.NewServer(logger, cfg.TFTP, udp.NewConnector(), responseHandling); err != nil {
panic(err.Error())
}
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
defer cancel()
err = srv.ListenAndServe(ctx)
return
}