From faa5ca8fab23176d390e9522f1485d467851545b Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 06 Apr 2025 01:55:21 +0800 Subject: [PATCH] Move stuff into internal/unsorted --- Makefile | 10 ++++++++-- acl.go => internal/unsorted/acl.go | 2 +- cmd/forge/main.go | 9 ++++++--- config.go => internal/unsorted/config.go | 2 +- database.go => internal/unsorted/database.go | 2 +- fedauth.go => internal/unsorted/fedauth.go | 2 +- git_hooks_handle_linux.go => internal/unsorted/git_hooks_handle_linux.go | 2 +- git_hooks_handle_other.go => internal/unsorted/git_hooks_handle_other.go | 2 +- git_init.go => internal/unsorted/git_init.go | 2 +- git_misc.go => internal/unsorted/git_misc.go | 2 +- git_plumbing.go => internal/unsorted/git_plumbing.go | 2 +- git_ref.go => internal/unsorted/git_ref.go | 2 +- http_auth.go => internal/unsorted/http_auth.go | 2 +- http_handle_branches.go => internal/unsorted/http_handle_branches.go | 2 +- http_handle_group_index.go => internal/unsorted/http_handle_group_index.go | 2 +- http_handle_index.go => internal/unsorted/http_handle_index.go | 2 +- http_handle_login.go => internal/unsorted/http_handle_login.go | 2 +- http_handle_repo_commit.go => internal/unsorted/http_handle_repo_commit.go | 2 +- http_handle_repo_contrib_index.go => internal/unsorted/http_handle_repo_contrib_index.go | 2 +- http_handle_repo_contrib_one.go => internal/unsorted/http_handle_repo_contrib_one.go | 2 +- http_handle_repo_index.go => internal/unsorted/http_handle_repo_index.go | 2 +- http_handle_repo_info.go => internal/unsorted/http_handle_repo_info.go | 2 +- http_handle_repo_log.go => internal/unsorted/http_handle_repo_log.go | 2 +- http_handle_repo_raw.go => internal/unsorted/http_handle_repo_raw.go | 2 +- http_handle_repo_tree.go => internal/unsorted/http_handle_repo_tree.go | 2 +- http_handle_repo_upload_pack.go => internal/unsorted/http_handle_repo_upload_pack.go | 2 +- http_handle_users.go => internal/unsorted/http_handle_users.go | 2 +- http_server.go => internal/unsorted/http_server.go | 2 +- http_template.go => internal/unsorted/http_template.go | 2 +- internal/embed/.gitignore | 6 ++++++ internal/embed/embed.go | 10 ++++++++++ internal/render/readme.go | 2 +- internal/unsorted/version.go | 3 +++ lmtp_handle_patch.go => internal/unsorted/lmtp_handle_patch.go | 2 +- lmtp_server.go => internal/unsorted/lmtp_server.go | 2 +- remote_url.go => internal/unsorted/remote_url.go | 2 +- resources.go => internal/unsorted/resources.go | 15 ++++----------- server.go => internal/unsorted/server.go | 21 ++++++++++++--------- ssh_handle_receive_pack.go => internal/unsorted/ssh_handle_receive_pack.go | 2 +- ssh_handle_upload_pack.go => internal/unsorted/ssh_handle_upload_pack.go | 2 +- ssh_server.go => internal/unsorted/ssh_server.go | 2 +- ssh_utils.go => internal/unsorted/ssh_utils.go | 2 +- users.go => internal/unsorted/users.go | 2 +- version.go | 3 --- diff --git a/Makefile b/Makefile index d4f868a87a90e27ebe74f59f227867a5aa466740..8954b494bb5aa3179fe7c939dad79f1e494a12a1 100644 --- a/Makefile +++ b/Makefile @@ -14,15 +14,17 @@ MAN_PAGES = lindenii-forge.5 lindenii-forge-hookc.1 lindenii-forge.1 lindenii-forge-mail.5 VERSION = $(shell git describe --tags --always --dirty) SOURCE_FILES = $(shell git ls-files) +EMBED = git2d/git2d hookc/hookc source.tar.gz LICENSE $(wildcard static/*) $(wildcard templates/*) +EMBED_ = $(EMBED:%=internal/embed/%) -forge: source.tar.gz hookc/hookc git2d/git2d $(SOURCE_FILES) +forge: $(EMBED_) $(SOURCE_FILES) CGO_ENABLED=0 go build -o forge -ldflags '-extldflags "-f no-PIC -static" -X "go.lindenii.runxiyu.org/forge.version=$(VERSION)"' -tags 'osusergo netgo static_build' ./cmd/forge utils/colb: hookc/hookc: -git2d/git2d: git2d/*.c +git2d/git2d: $(wildcard git2d/*.c) $(CC) $(CFLAGS) -o git2d/git2d $^ $(shell pkg-config --cflags --libs libgit2) -lpthread clean: @@ -31,3 +33,7 @@ source.tar.gz: $(SOURCE_FILES) rm -f source.tar.gz git ls-files -z | xargs -0 tar -czf source.tar.gz + +internal/embed/%: % + mkdir -p $(shell dirname $@) + cp $^ $@ diff --git a/acl.go b/internal/unsorted/acl.go rename from acl.go rename to internal/unsorted/acl.go index aaf190ba79f2a74c6fea09f58154b39eb3ac0865..c2e887d9247601eeb773bce6b66d07f613c6c660 100644 --- a/acl.go +++ b/internal/unsorted/acl.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "context" diff --git a/cmd/forge/main.go b/cmd/forge/main.go index 07a9bfd6854106e4833b7a7e0f8d1f3e80884160..5a2394798fd8e756fa3a010673418560797b5c4d 100644 --- a/cmd/forge/main.go +++ b/cmd/forge/main.go @@ -6,7 +6,7 @@ import ( "flag" - "go.lindenii.runxiyu.org/forge" + "go.lindenii.runxiyu.org/forge/internal/unsorted" ) func main() { @@ -17,7 +17,10 @@ "path to configuration file", ) flag.Parse() - s := forge.NewServer(*configPath) + s, err := unsorted.NewServer(*configPath) + if err != nil { + panic(err) + } - s.Run() + panic(s.Run()) } diff --git a/config.go b/internal/unsorted/config.go rename from config.go rename to internal/unsorted/config.go index 8ed6eb73110bd12f85af327c7d6443fbee37ccef..a2c0eb72796395156a4bde033b95203e4ce74a6e 100644 --- a/config.go +++ b/internal/unsorted/config.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "bufio" diff --git a/database.go b/internal/unsorted/database.go rename from database.go rename to internal/unsorted/database.go index b1aca72768eca9f6e29f508645cc5d21e5ca002c..222b0c41d66e4e133cbab4288f4a9d808bc67ac4 100644 --- a/database.go +++ b/internal/unsorted/database.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "context" diff --git a/fedauth.go b/internal/unsorted/fedauth.go rename from fedauth.go rename to internal/unsorted/fedauth.go index 7866e581416f7b73d6d0e28125f82a730abaea92..f54649b5006a262b213b0049ad082fb150c3e5ef 100644 --- a/fedauth.go +++ b/internal/unsorted/fedauth.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "bufio" diff --git a/git_hooks_handle_linux.go b/internal/unsorted/git_hooks_handle_linux.go rename from git_hooks_handle_linux.go rename to internal/unsorted/git_hooks_handle_linux.go index fa4f86f198a5a799b57297ce78e6242d464f99e4..de45e03b65e93a82c7143d64e6427d9af122e8fb 100644 --- a/git_hooks_handle_linux.go +++ b/internal/unsorted/git_hooks_handle_linux.go @@ -3,7 +3,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu // //go:build linux -package forge +package unsorted import ( "bytes" diff --git a/git_hooks_handle_other.go b/internal/unsorted/git_hooks_handle_other.go rename from git_hooks_handle_other.go rename to internal/unsorted/git_hooks_handle_other.go index da40bb68ed10f6dcabb254465e2ca396be9a8899..dd4662218b0686752df66ae076d82f67333c4537 100644 --- a/git_hooks_handle_other.go +++ b/internal/unsorted/git_hooks_handle_other.go @@ -3,7 +3,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu // //go:build !linux -package forge +package unsorted import ( "bytes" diff --git a/git_init.go b/internal/unsorted/git_init.go rename from git_init.go rename to internal/unsorted/git_init.go index d1922eed2757251cbd81c60efebd7e595d6f2c0a..a9bba78b138ff93f8c71473bb8b8d2fa9bf18665 100644 --- a/git_init.go +++ b/internal/unsorted/git_init.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "github.com/go-git/go-git/v5" diff --git a/git_misc.go b/internal/unsorted/git_misc.go rename from git_misc.go rename to internal/unsorted/git_misc.go index 83ee11c1a38d755008f0ce46e0b807ad94bee81a..ceda3d123e29e505d55068b2c6551d6580fdc569 100644 --- a/git_misc.go +++ b/internal/unsorted/git_misc.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "context" diff --git a/git_plumbing.go b/internal/unsorted/git_plumbing.go rename from git_plumbing.go rename to internal/unsorted/git_plumbing.go index 8c73a937cce038e71af301e9039c7a25add130c5..5cb30b794935a85b10030b97f75437ba36747788 100644 --- a/git_plumbing.go +++ b/internal/unsorted/git_plumbing.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "bytes" diff --git a/git_ref.go b/internal/unsorted/git_ref.go rename from git_ref.go rename to internal/unsorted/git_ref.go index 476dde04bdc42da371e5789ba16b6b5affe66c18..d9735ba2d7b2dcfb3b71f7f9cbf4d452da166e77 100644 --- a/git_ref.go +++ b/internal/unsorted/git_ref.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "github.com/go-git/go-git/v5" diff --git a/http_auth.go b/internal/unsorted/http_auth.go rename from http_auth.go rename to internal/unsorted/http_auth.go index 44e087dc79fa4b13e44b214c731e4009744cd7a1..b0afa05db9b8fbcd2ed1c425c69ba967621229e9 100644 --- a/http_auth.go +++ b/internal/unsorted/http_auth.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "net/http" diff --git a/http_handle_branches.go b/internal/unsorted/http_handle_branches.go rename from http_handle_branches.go rename to internal/unsorted/http_handle_branches.go index 7709d4e9371f4e2716a0cbbaa3cdeb475408ad5e..04a9f316178334a04219c6ca4c592aac01a401c4 100644 --- a/http_handle_branches.go +++ b/internal/unsorted/http_handle_branches.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "net/http" diff --git a/http_handle_group_index.go b/internal/unsorted/http_handle_group_index.go rename from http_handle_group_index.go rename to internal/unsorted/http_handle_group_index.go index 5d2edce60abba50a10c33e9318826f162047693b..41eba24fe328a7add5fffc4e130fdf89600d8f0f 100644 --- a/http_handle_group_index.go +++ b/internal/unsorted/http_handle_group_index.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "errors" diff --git a/http_handle_index.go b/internal/unsorted/http_handle_index.go rename from http_handle_index.go rename to internal/unsorted/http_handle_index.go index c1efd98debb5aa6ec920e56bfd99c36b52618c2c..458fbb4381b78223aaf7a90b4bad813a4dea86da 100644 --- a/http_handle_index.go +++ b/internal/unsorted/http_handle_index.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "net/http" diff --git a/http_handle_login.go b/internal/unsorted/http_handle_login.go rename from http_handle_login.go rename to internal/unsorted/http_handle_login.go index 4b7cacf744b0cf687f98c138c0af9ad9f3ad1cc2..5386e3a50b2bf7a00fa87af764eaa578a0267686 100644 --- a/http_handle_login.go +++ b/internal/unsorted/http_handle_login.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "crypto/rand" diff --git a/http_handle_repo_commit.go b/internal/unsorted/http_handle_repo_commit.go rename from http_handle_repo_commit.go rename to internal/unsorted/http_handle_repo_commit.go index 22ee20d1e4365851d463249c82d9e99eb685d629..44f8f5472230799f5d72323604de56dfb15cbff7 100644 --- a/http_handle_repo_commit.go +++ b/internal/unsorted/http_handle_repo_commit.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "fmt" diff --git a/http_handle_repo_contrib_index.go b/internal/unsorted/http_handle_repo_contrib_index.go rename from http_handle_repo_contrib_index.go rename to internal/unsorted/http_handle_repo_contrib_index.go index 7bdcb49098403ddce48f243a162fd98e0b4b91fc..4db3846786fa876429a8ad9324d17991e03417a5 100644 --- a/http_handle_repo_contrib_index.go +++ b/internal/unsorted/http_handle_repo_contrib_index.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "net/http" diff --git a/http_handle_repo_contrib_one.go b/internal/unsorted/http_handle_repo_contrib_one.go rename from http_handle_repo_contrib_one.go rename to internal/unsorted/http_handle_repo_contrib_one.go index 280dca80da120c597eca3abdd96adb844c7026e0..fb9989b77084866324db856008a80e1367fa4121 100644 --- a/http_handle_repo_contrib_one.go +++ b/internal/unsorted/http_handle_repo_contrib_one.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "net/http" diff --git a/http_handle_repo_index.go b/internal/unsorted/http_handle_repo_index.go rename from http_handle_repo_index.go rename to internal/unsorted/http_handle_repo_index.go index b564286dedf6204e8c74bf4ab938d48428bca58b..f2bb480e5d5652baabf06922b1be769147033f61 100644 --- a/http_handle_repo_index.go +++ b/internal/unsorted/http_handle_repo_index.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "net/http" diff --git a/http_handle_repo_info.go b/internal/unsorted/http_handle_repo_info.go rename from http_handle_repo_info.go rename to internal/unsorted/http_handle_repo_info.go index 303fad7e6e2028acb0258e08d95cf3cc44e75290..e23b1d290ff808e333845fa5befbc29ff9abc0a1 100644 --- a/http_handle_repo_info.go +++ b/internal/unsorted/http_handle_repo_info.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "fmt" diff --git a/http_handle_repo_log.go b/internal/unsorted/http_handle_repo_log.go rename from http_handle_repo_log.go rename to internal/unsorted/http_handle_repo_log.go index fbc747899ee0fa657e397b085c894825d3c20a54..c25c60b5122a4314407c6eba0820af39a85ebaa4 100644 --- a/http_handle_repo_log.go +++ b/internal/unsorted/http_handle_repo_log.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "net/http" diff --git a/http_handle_repo_raw.go b/internal/unsorted/http_handle_repo_raw.go rename from http_handle_repo_raw.go rename to internal/unsorted/http_handle_repo_raw.go index 286cbdf345a6a84d7a66f7110e65ec5f56922230..7849d481b6fe4570d5457083f17ad3bb0b7ddaf6 100644 --- a/http_handle_repo_raw.go +++ b/internal/unsorted/http_handle_repo_raw.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "fmt" diff --git a/http_handle_repo_tree.go b/internal/unsorted/http_handle_repo_tree.go rename from http_handle_repo_tree.go rename to internal/unsorted/http_handle_repo_tree.go index d127e5dc48c47978c466cb3ae193e3c08270d38a..cbbba98ac72a1a89303d1c6d8b7dc9ca43e583e9 100644 --- a/http_handle_repo_tree.go +++ b/internal/unsorted/http_handle_repo_tree.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "html/template" diff --git a/http_handle_repo_upload_pack.go b/internal/unsorted/http_handle_repo_upload_pack.go rename from http_handle_repo_upload_pack.go rename to internal/unsorted/http_handle_repo_upload_pack.go index 475c0a2d37800149a4ace0bec3471a30387ae5ac..df8bef4ddddd66ca97852fe21a7f8af5fca73b41 100644 --- a/http_handle_repo_upload_pack.go +++ b/internal/unsorted/http_handle_repo_upload_pack.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "io" diff --git a/http_handle_users.go b/internal/unsorted/http_handle_users.go rename from http_handle_users.go rename to internal/unsorted/http_handle_users.go index 816d7032b8aafb1a97f44d88877b030c4f4dd7b9..7b0f6570958c05e2d36186c5fac5c03f02c88d51 100644 --- a/http_handle_users.go +++ b/internal/unsorted/http_handle_users.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "net/http" diff --git a/http_server.go b/internal/unsorted/http_server.go rename from http_server.go rename to internal/unsorted/http_server.go index 717f223dc76cde89e3bde6b9d380d6db5226c63a..6710df35340ae3464619c067bce5e83cfced354d 100644 --- a/http_server.go +++ b/internal/unsorted/http_server.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "errors" diff --git a/http_template.go b/internal/unsorted/http_template.go rename from http_template.go rename to internal/unsorted/http_template.go index d6af9fbb69bff6fbb4e8ae35ee078cc767c6798a..db44e4c4d19a96b86415e99ce542b9ce0e0d3c65 100644 --- a/http_template.go +++ b/internal/unsorted/http_template.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "log/slog" diff --git a/internal/embed/.gitignore b/internal/embed/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..32f7afffc98e211f563a3d79c623070d3b8b3641 --- /dev/null +++ b/internal/embed/.gitignore @@ -0,0 +1,6 @@ +/source.tar.gz +/hookc/hookc +/git2d/git2d +/static +/templates +/LICENSE diff --git a/internal/embed/embed.go b/internal/embed/embed.go new file mode 100644 index 0000000000000000000000000000000000000000..76b01929a3501ab4edcea62266df1c5b4272908d --- /dev/null +++ b/internal/embed/embed.go @@ -0,0 +1,10 @@ +package embed + +import "embed" + +//go:embed LICENSE source.tar.gz +var Source embed.FS + +//go:embed templates/* static/* +//go:embed hookc/hookc git2d/git2d +var Resources embed.FS diff --git a/internal/render/readme.go b/internal/render/readme.go index aecd2f7a89b3cef2232f0ec0e50863e22de97c20..ac609813fa799f6d46dc791a4b483be7ecbfee63 100644 --- a/internal/render/readme.go +++ b/internal/render/readme.go @@ -16,7 +16,7 @@ "github.com/yuin/goldmark/extension" "go.lindenii.runxiyu.org/forge/internal/misc" ) -var markdownConverter = goldmark.New(goldmark.WithExtensions(extension.GFM)) +var markdownConverter = goldmark.New(goldmark.WithExtensions(extension.GFM)) //nolint:gochecknoglobals // renderReadme renders and sanitizes README content from a byte slice and filename. func Readme(data []byte, filename string) (string, template.HTML) { diff --git a/internal/unsorted/version.go b/internal/unsorted/version.go new file mode 100644 index 0000000000000000000000000000000000000000..fccf52c7dfd8db68a829d4f1c7002e7713745d67 --- /dev/null +++ b/internal/unsorted/version.go @@ -0,0 +1,3 @@ +package unsorted + +var version = "unknown" diff --git a/lmtp_handle_patch.go b/internal/unsorted/lmtp_handle_patch.go rename from lmtp_handle_patch.go rename to internal/unsorted/lmtp_handle_patch.go index 6841444fe1be07c4ef3e2f86cf2ad5d93a920166..1a234229905fa81fb637c569c8db2f98bd669a50 100644 --- a/lmtp_handle_patch.go +++ b/internal/unsorted/lmtp_handle_patch.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "bytes" diff --git a/lmtp_server.go b/internal/unsorted/lmtp_server.go rename from lmtp_server.go rename to internal/unsorted/lmtp_server.go index 593dc5a2b1c66380a384f43914627725679c289c..13c74c8ba73c5637ac01ddc927c94735bfc21de9 100644 --- a/lmtp_server.go +++ b/internal/unsorted/lmtp_server.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu // SPDX-FileCopyrightText: Copyright (c) 2024 Robin Jarry -package forge +package unsorted import ( "bytes" diff --git a/remote_url.go b/internal/unsorted/remote_url.go rename from remote_url.go rename to internal/unsorted/remote_url.go index a9d8bf286f7fe3ba1a44a30d7ae852c372a75e0d..51740c4d87494484410ad21fa31b96574cb9cfdc 100644 --- a/remote_url.go +++ b/internal/unsorted/remote_url.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "net/url" diff --git a/resources.go b/internal/unsorted/resources.go rename from resources.go rename to internal/unsorted/resources.go index 514c0ae30c165c22066caa3adf67f21357be924f..d09ee609588b332d4601f860a110ff331585a1ad 100644 --- a/resources.go +++ b/internal/unsorted/resources.go @@ -1,25 +1,18 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( - "embed" "html/template" "io/fs" "github.com/tdewolff/minify/v2" "github.com/tdewolff/minify/v2/html" + "go.lindenii.runxiyu.org/forge/internal/embed" "go.lindenii.runxiyu.org/forge/internal/misc" ) -//go:embed LICENSE source.tar.gz -var embeddedSourceFS embed.FS - -//go:embed templates/* static/* -//go:embed hookc/hookc git2d/git2d -var embeddedResourcesFS embed.FS - // loadTemplates minifies and loads HTML templates. func (s *Server) loadTemplates() (err error) { minifier := minify.New() @@ -37,12 +30,12 @@ "dereference_error": misc.DereferenceOrZero[error], "minus": misc.Minus, }) - err = fs.WalkDir(embeddedResourcesFS, "templates", func(path string, d fs.DirEntry, err error) error { + err = fs.WalkDir(embed.Resources, "templates", func(path string, d fs.DirEntry, err error) error { if err != nil { return err } if !d.IsDir() { - content, err := fs.ReadFile(embeddedResourcesFS, path) + content, err := fs.ReadFile(embed.Resources, path) if err != nil { return err } diff --git a/server.go b/internal/unsorted/server.go rename from server.go rename to internal/unsorted/server.go index 3a90e1c869ee758199fe7aa076c8a97f374388bc..12da5cb770c56923dd5462f33f6561b2356f59cf 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 -package forge +package unsorted import ( "errors" @@ -18,6 +18,7 @@ "syscall" "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 @@ 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 @@ // Some other ones are populated after config parsing } 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 { diff --git a/ssh_handle_receive_pack.go b/internal/unsorted/ssh_handle_receive_pack.go rename from ssh_handle_receive_pack.go rename to internal/unsorted/ssh_handle_receive_pack.go index de6843a6ff121f5bb4fb0b6d1a33bf7a2e17cd9d..a354273185c9a33ca7d05acf2fe520d573fc6270 100644 --- a/ssh_handle_receive_pack.go +++ b/internal/unsorted/ssh_handle_receive_pack.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "errors" diff --git a/ssh_handle_upload_pack.go b/internal/unsorted/ssh_handle_upload_pack.go rename from ssh_handle_upload_pack.go rename to internal/unsorted/ssh_handle_upload_pack.go index 34a1d9e651da875cbf86b7676fd2d26e6860eef0..735a05352ef13f3b478145cfe5adf49627a53ab4 100644 --- a/ssh_handle_upload_pack.go +++ b/internal/unsorted/ssh_handle_upload_pack.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "fmt" diff --git a/ssh_server.go b/internal/unsorted/ssh_server.go rename from ssh_server.go rename to internal/unsorted/ssh_server.go index 45ed7034f14701d0fb806dda484531512708d123..eb4d09d2f6e838cc037a1bdfd08e76cfd5f8eeb5 100644 --- a/ssh_server.go +++ b/internal/unsorted/ssh_server.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "fmt" diff --git a/ssh_utils.go b/internal/unsorted/ssh_utils.go rename from ssh_utils.go rename to internal/unsorted/ssh_utils.go index 7aeedfff42665c68245c63a54f43dc57641f90ab..d9850d215d5cee3d96bd79ee27535461904e113a 100644 --- a/ssh_utils.go +++ b/internal/unsorted/ssh_utils.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "context" diff --git a/users.go b/internal/unsorted/users.go rename from users.go rename to internal/unsorted/users.go index 2b529f39ab1bdfaa3f1f57589b32550848c86850..0f72eed8bdb8e6649f979da6b204fae080ca0eef 100644 --- a/users.go +++ b/internal/unsorted/users.go @@ -1,7 +1,7 @@ // SPDX-License-Identifier: AGPL-3.0-only // SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu -package forge +package unsorted import ( "context" diff --git a/version.go b/version.go deleted file mode 100644 index 555fe2ad33caea6cea269ce4d52fa4a85decc6f1..0000000000000000000000000000000000000000 --- a/version.go +++ /dev/null @@ -1,3 +0,0 @@ -package forge - -var version = "unknown" -- 2.48.1