diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-06 01:55:21 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-06 02:08:58 +0800 |
commit | faa5ca8fab23176d390e9522f1485d467851545b (patch) | |
tree | d3b1d081e0ea5e7f71a94dc1d301e2540a8abcc8 /internal/unsorted/server.go | |
parent | Slight refactor on NewServer (diff) | |
download | forge-0.1.28.tar.gz forge-0.1.28.tar.zst forge-0.1.28.zip |
Move stuff into internal/unsortedv0.1.28
Diffstat (limited to '')
-rw-r--r-- | internal/unsorted/server.go (renamed from server.go) | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/server.go b/internal/unsorted/server.go index 3a90e1c..12da5cb 100644 --- a/server.go +++ b/internal/unsorted/server.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> -package forge +package unsorted import ( "errors" @@ -18,6 +18,7 @@ import ( "time" "go.lindenii.runxiyu.org/forge/internal/database" + "go.lindenii.runxiyu.org/forge/internal/embed" "go.lindenii.runxiyu.org/forge/internal/irc" "go.lindenii.runxiyu.org/forge/internal/misc" "go.lindenii.runxiyu.org/lindenii-common/cmap" @@ -49,18 +50,20 @@ type Server struct { ready bool } -func (s *Server) NewServer(configPath string) error { +func NewServer(configPath string) (*Server, error) { + s := &Server{} + if err := s.loadConfig(configPath); err != nil { - return err + return s, err } s.sourceHandler = http.StripPrefix( "/-/source/", - http.FileServer(http.FS(embeddedSourceFS)), + http.FileServer(http.FS(embed.Source)), ) - staticFS, err := fs.Sub(embeddedResourcesFS, "static") + staticFS, err := fs.Sub(embed.Resources, "static") if err != nil { - return err + return s, err } s.staticHandler = http.StripPrefix("/-/static/", http.FileServer(http.FS(staticFS))) s.globalData = map[string]any{ @@ -71,13 +74,13 @@ func (s *Server) NewServer(configPath string) error { } misc.NoneOrPanic(s.loadTemplates()) - misc.NoneOrPanic(misc.DeployBinary(misc.FirstOrPanic(embeddedResourcesFS.Open("git2d/git2d")), s.config.Git.DaemonPath)) - misc.NoneOrPanic(misc.DeployBinary(misc.FirstOrPanic(embeddedResourcesFS.Open("hookc/hookc")), filepath.Join(s.config.Hooks.Execs, "pre-receive"))) + misc.NoneOrPanic(misc.DeployBinary(misc.FirstOrPanic(embed.Resources.Open("git2d/git2d")), s.config.Git.DaemonPath)) + misc.NoneOrPanic(misc.DeployBinary(misc.FirstOrPanic(embed.Resources.Open("hookc/hookc")), filepath.Join(s.config.Hooks.Execs, "pre-receive"))) misc.NoneOrPanic(os.Chmod(filepath.Join(s.config.Hooks.Execs, "pre-receive"), 0o755)) s.ready = true - return nil + return s, nil } func (s *Server) Run() error { |