--- a/hgweb/hgweb.go Mon Mar 07 01:34:20 2022 -0600
+++ b/hgweb/hgweb.go Mon Mar 07 01:38:28 2022 -0600
@@ -3,44 +3,15 @@
- log "github.com/sirupsen/logrus"
"keep.imfreedom.org/grim/hgkeeper/access"
- "keep.imfreedom.org/grim/hgkeeper/hg"
- hgkHttp "keep.imfreedom.org/grim/hgkeeper/http"
- externalHostname string
-func NewServer(listenAddr string, externalHostname, externalPort string) (*Server, error) {
- listenAddr: listenAddr,
- externalHostname: externalHostname,
- externalPort: externalPort,
func (s *Server) createConfig() error {
configPath, err := ioutil.TempFile("", "hgkeeper-hgweb-*.config")
@@ -102,49 +73,3 @@
-func (s *Server) Listen() error {
- if err := s.createConfig(); err != nil {
- if err := s.createCGI(); err != nil {
- templatesDir, err := hg.TemplatesDir()
- staticPath := filepath.Join(templatesDir, "static")
- log.Infof("serving static files from %s", staticPath)
- fileServer := http.FileServer(http.Dir(staticPath))
- mux := http.NewServeMux()
- if s.externalHostname != "" {
- mux.Handle("/ssh/authorized_keys", hgkHttp.AuthorizedKeysHandler(s.externalHostname, s.externalPort))
- log.Infof("added /ssh/authorized_keys endpoint with external hostname %s and export port %s", s.externalHostname, s.externalPort)
- log.Infof("no external hostname specified, not adding /ssh/authorized_keys endpoint")
- mux.Handle("/static/", http.StripPrefix("/static", fileServer))
- mux.Handle("/", &cgi.Handler{Path: s.cgiPath})
- s.server.Handler = Logger(mux)
- log.Infof("http listening on %s", s.listenAddr)
- return s.server.ListenAndServe()
-func (s *Server) Close() {
- if err := os.Remove(s.cgiPath); err != nil {
- log.Warnf("failed to remove temporary cgi file %q: %v", s.cgiPath, err)
- if err := s.server.Close(); err != nil {
- log.Warnf("failed to shutdown http server: %v", err)