aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--config.go34
-rw-r--r--forge.scfg4
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--handle_index.go8
-rw-r--r--main.go37
-rw-r--r--resources.go32
-rw-r--r--static/style.css0
-rw-r--r--templates/repo.html0
10 files changed, 120 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e90b0c9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/forge
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..a38fd25
--- /dev/null
+++ b/config.go
@@ -0,0 +1,34 @@
+package main
+
+import (
+ "bufio"
+ "os"
+
+ "go.lindenii.runxiyu.org/lindenii-common/scfg"
+)
+
+var config struct {
+ HTTP struct {
+ Net string `scfg:"net"`
+ Addr string `scfg:"addr"`
+ } `scfg:"http"`
+ DB struct {
+ Type string `scfg:"type"`
+ Conn string `scfg:"conn"`
+ } `scfg:"db"`
+}
+
+func load_config(path string) (err error) {
+ config_file, err := os.Open(path)
+ if err != nil {
+ return err
+ }
+
+ decoder := scfg.NewDecoder(bufio.NewReader(config_file))
+ err = decoder.Decode(&config)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
diff --git a/forge.scfg b/forge.scfg
new file mode 100644
index 0000000..dea1ee6
--- /dev/null
+++ b/forge.scfg
@@ -0,0 +1,4 @@
+http {
+ net tcp
+ addr :8080
+}
diff --git a/go.mod b/go.mod
index 7df45b7..931720e 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,5 @@
module go.lindenii.runxiyu.org/forge
go 1.23.5
+
+require go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250113062520-2daa71bfa256
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..19c88e0
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,2 @@
+go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250113062520-2daa71bfa256 h1:LCekcmEfZRfuuLMKUMT2TCgdXQRPIjxalibQIzHjzIo=
+go.lindenii.runxiyu.org/lindenii-common v0.0.0-20250113062520-2daa71bfa256/go.mod h1:bOxuuGXA3UpbLb1lKohr2j2MVcGGLcqfAprGx9VCkMA=
diff --git a/handle_index.go b/handle_index.go
new file mode 100644
index 0000000..b9a8a0c
--- /dev/null
+++ b/handle_index.go
@@ -0,0 +1,8 @@
+package main
+
+import (
+ "net/http"
+)
+
+func handle_index(w http.ResponseWriter, r *http.Request) {
+}
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..3467f3f
--- /dev/null
+++ b/main.go
@@ -0,0 +1,37 @@
+package main
+
+import (
+ "flag"
+ "net"
+ "net/http"
+
+ "go.lindenii.runxiyu.org/lindenii-common/clog"
+)
+
+func main() {
+ config_path := flag.String(
+ "config",
+ "/etc/lindenii/forge.scfg",
+ "path to configuration file",
+ )
+ flag.Parse()
+
+ err := load_config(*config_path)
+ if err != nil {
+ clog.Fatal(1, "Loading configuration: "+err.Error())
+ }
+
+ err = load_templates()
+ if err != nil {
+ clog.Fatal(1, "Loading templates: "+err.Error())
+ }
+
+ http.HandleFunc("/{$}", handle_index)
+
+ listener, err := net.Listen(config.HTTP.Net, config.HTTP.Addr)
+ if err != nil {
+ clog.Fatal(1, "Listening: "+err.Error())
+ }
+
+ http.Serve(listener, nil)
+}
diff --git a/resources.go b/resources.go
new file mode 100644
index 0000000..737a079
--- /dev/null
+++ b/resources.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "embed"
+ "html/template"
+ "io/fs"
+ "net/http"
+)
+
+//go:embed templates/* static/*
+var resources_fs embed.FS
+
+var templates *template.Template
+
+func load_templates() (err error) {
+ templates, err = template.ParseFS(resources_fs, "templates/*")
+ return err
+}
+
+func serve_static() (err error) {
+ static_fs, err := fs.Sub(resources_fs, "static")
+ if err != nil {
+ return err
+ }
+ http.Handle("/static/",
+ http.StripPrefix(
+ "/static/",
+ http.FileServer(http.FS(static_fs)),
+ ),
+ )
+ return nil
+}
diff --git a/static/style.css b/static/style.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/static/style.css
diff --git a/templates/repo.html b/templates/repo.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/templates/repo.html