forked from tangled.org/core
this repo has no description

guard: read the motd from a file

Signed-off-by: dusk <y.bera003.06@protonmail.com>

Change-Id: kvuxwxxzvvqtvypqzlotlwkqmuttqwun

Changed files
+19 -3
guard
+19 -3
guard/guard.go
···
import (
"context"
"fmt"
"log/slog"
"net/http"
"net/url"
···
Usage: "internal API endpoint",
Value: "http://localhost:5444",
},
},
}
}
···
gitDir := cmd.String("git-dir")
logPath := cmd.String("log-path")
endpoint := cmd.String("internal-api")
logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
···
"fullPath", fullPath,
"client", clientIP)
-
if gitCommand == "git-upload-pack" {
-
fmt.Fprintf(os.Stderr, "\x02%s\n", "Welcome to this knot!")
} else {
-
fmt.Fprintf(os.Stderr, "%s\n", "Welcome to this knot!")
}
gitCmd := exec.Command(gitCommand, fullPath)
gitCmd.Stdout = os.Stdout
···
import (
"context"
+
"errors"
"fmt"
+
"io"
"log/slog"
"net/http"
"net/url"
···
Usage: "internal API endpoint",
Value: "http://localhost:5444",
},
+
&cli.StringFlag{
+
Name: "motd-file",
+
Usage: "path to message of the day file",
+
Value: "/home/git/motd",
+
},
},
}
}
···
gitDir := cmd.String("git-dir")
logPath := cmd.String("log-path")
endpoint := cmd.String("internal-api")
+
motdFile := cmd.String("motd-file")
logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
···
"fullPath", fullPath,
"client", clientIP)
+
var motdReader io.Reader
+
if reader, err := os.Open(motdFile); err != nil {
+
if !errors.Is(err, os.ErrNotExist) {
+
l.Error("failed to read motd file", "error", err)
+
}
+
motdReader = strings.NewReader("Welcome to this knot!\n")
} else {
+
motdReader = reader
+
}
+
if gitCommand == "git-upload-pack" {
+
io.WriteString(os.Stderr, "\x02")
}
+
io.Copy(os.Stderr, motdReader)
gitCmd := exec.Command(gitCommand, fullPath)
gitCmd.Stdout = os.Stdout