Hi… I am well aware that this diff view is very suboptimal. It will be fixed when the refactored server comes along!
git_init.go: git_bare_init_with_default_hooks
package main
import (
"bufio"
"context"
"errors"
"os"
"github.com/jackc/pgx/v5/pgxpool"
"go.lindenii.runxiyu.org/lindenii-common/scfg"
)
var database *pgxpool.Pool
var err_unsupported_database_type = errors.New("Unsupported database type")
var config struct {
HTTP struct {
Net string `scfg:"net"`
Addr string `scfg:"addr"`
CookieExpiry int `scfg:"cookie_expiry"`
Root string `scfg:"root"`
} `scfg:"http"`
Git struct {
HooksSocket string `scfg:"hooks_socket"`
} `scfg:"git"`
Hooks struct {
Socket string `scfg:"socket"`
Execs string `scfg:"execs"`
} `scfg:"hooks"`
SSH struct {
Net string `scfg:"net"`
Addr string `scfg:"addr"`
Key string `scfg:"key"`
Root string `scfg:"root"`
} `scfg:"ssh"`
General struct {
Title string `scfg:"title"`
} `scfg:"general"`
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
}
defer config_file.Close()
decoder := scfg.NewDecoder(bufio.NewReader(config_file))
err = decoder.Decode(&config)
if err != nil {
return err
}
if config.DB.Type != "postgres" {
return err_unsupported_database_type
}
database, err = pgxpool.New(context.Background(), config.DB.Conn)
if err != nil {
return err
}
global_data["forge_title"] = config.General.Title
return nil
}
http {
net tcp
addr :8080
cookie_expiry 604800
root https://forge.example.org
}
ssh {
net tcp
addr :2222
key /etc/lindenii/ssh_host_ed25519_key
root ssh://forge.example.org:2222
}
general {
title "Test Forge"
}
db {
type postgres
conn postgresql:///lindenii-forge?host=/var/run/postgresql
}
git {
hooks_socket /var/run/lindenii/forge/hooks.sock
hooks {
socket /var/run/lindenii/forge/hooks.sock
execs /usr/libexec/lindenii/forge/hooks
}
package main
import (
"github.com/go-git/go-git/v5"
git_format_config "github.com/go-git/go-git/v5/plumbing/format/config"
)
func git_bare_init_with_default_hooks(repo_path string) (err error) {
repo, err := git.PlainInit(repo_path, true)
if err != nil {
return err
}
git_config, err := repo.Config()
if err != nil {
return err
}
git_config.Raw.SetOption("core", git_format_config.NoSubsection, "hooksPath", config.Hooks.Execs)
err = repo.SetConfig(git_config)
if err != nil {
return err
}
return nil
}