aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-24 16:23:56 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-24 16:23:56 -0700
commita2ef262a164fc735b9b8471ac0c8001eea2b9bf6 (patch)
tree9a24fc5949df1183895a125e09cb262cdf79b073 /cmd
parenta55350daaf83498b7a237c027ad0dd2377f06fee (diff)
Refactoring, cleanup, test backfilling
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mobius-hotline-server/main.go51
1 files changed, 35 insertions, 16 deletions
diff --git a/cmd/mobius-hotline-server/main.go b/cmd/mobius-hotline-server/main.go
index c34dc71..bf64848 100644
--- a/cmd/mobius-hotline-server/main.go
+++ b/cmd/mobius-hotline-server/main.go
@@ -28,6 +28,7 @@ var logLevels = map[string]slog.Level{
"error": slog.LevelError,
}
+// Values swapped in by go-releaser at build time
var (
version = "dev"
commit = "none"
@@ -35,22 +36,22 @@ var (
)
func main() {
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, _ := context.WithCancel(context.Background())
// TODO: implement graceful shutdown by closing context
- // c := make(chan os.Signal, 1)
- // signal.Notify(c, os.Interrupt)
- // defer func() {
- // signal.Stop(c)
- // cancel()
- // }()
- // go func() {
- // select {
- // case <-c:
- // cancel()
- // case <-ctx.Done():
- // }
- // }()
+ //c := make(chan os.Signal, 1)
+ //signal.Notify(c, os.Interrupt)
+ //defer func() {
+ // signal.Stop(c)
+ // cancel()
+ //}()
+ //go func() {
+ // select {
+ // case <-c:
+ // cancel()
+ // case <-ctx.Done():
+ // }
+ //}()
netInterface := flag.String("interface", "", "IP addr of interface to listen on. Defaults to all interfaces.")
basePort := flag.Int("bind", defaultPort, "Base Hotline server port. File transfer port is base port + 1.")
@@ -129,7 +130,7 @@ func main() {
)
// Serve Hotline requests until program exit
- log.Fatal(srv.ListenAndServe(ctx, cancel))
+ log.Fatal(srv.ListenAndServe(ctx))
}
type statHandler struct {
@@ -166,7 +167,25 @@ func defaultConfigPath() string {
return cfgPath
}
-// TODO: Simplify this mess. Why is it so difficult to recursively copy a directory?
+// copyFile copies a file from src to dst. If dst does not exist, it is created.
+func copyFile(src, dst string) error {
+ sourceFile, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer sourceFile.Close()
+
+ destinationFile, err := os.Create(dst)
+ if err != nil {
+ return err
+ }
+ defer destinationFile.Close()
+
+ _, err = io.Copy(destinationFile, sourceFile)
+ return err
+}
+
+// copyDir recursively copies a directory tree, attempting to preserve permissions.
func copyDir(src, dst string) error {
entries, err := cfgTemplate.ReadDir(src)
if err != nil {