mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-05-17 04:31:38 +00:00
[breaking-change] Add a health check endpoint.
Also, simplify the listen endpoint configuration format.
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
[pages]
|
||||
protocol = "tcp"
|
||||
address = ":3333"
|
||||
|
||||
[caddy]
|
||||
protocol = "tcp"
|
||||
address = ":3334"
|
||||
[listen]
|
||||
pages = "tcp/:3000"
|
||||
caddy = "tcp/:3001"
|
||||
health = "tcp/:3002"
|
||||
|
||||
[wildcard]
|
||||
domain = "codeberg.page"
|
||||
|
||||
@@ -6,19 +6,17 @@ import (
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
)
|
||||
|
||||
type ListenConfig struct {
|
||||
Protocol string `toml:"protocol"`
|
||||
Address string `toml:"address"`
|
||||
}
|
||||
|
||||
type CacheConfig struct {
|
||||
MaxSize uint64 `toml:"max-size"` // in bytes
|
||||
MaxAge string `toml:"max-age"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Pages ListenConfig `toml:"pages"`
|
||||
Caddy ListenConfig `toml:"caddy"`
|
||||
Listen struct {
|
||||
Pages string `toml:"pages"`
|
||||
Caddy string `toml:"caddy"`
|
||||
Health string `toml:"health"`
|
||||
} `toml:"listen"`
|
||||
Wildcard struct {
|
||||
Domain string `toml:"domain"`
|
||||
CloneURL string `toml:"clone-url"`
|
||||
|
||||
11
src/health.go
Normal file
11
src/health.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ServeHealth(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintln(w, "ok")
|
||||
}
|
||||
22
src/main.go
22
src/main.go
@@ -6,12 +6,18 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var backend Backend
|
||||
|
||||
func serveHandler(name string, listen ListenConfig, serve func(http.ResponseWriter, *http.Request)) {
|
||||
listener, err := net.Listen(listen.Protocol, listen.Address)
|
||||
func serveHandler(name string, listen string, serve func(http.ResponseWriter, *http.Request)) {
|
||||
protocol, address, ok := strings.Cut(listen, "/")
|
||||
if !ok {
|
||||
log.Fatalf("%s: %s: malformed endpoint", name, listen)
|
||||
}
|
||||
|
||||
listener, err := net.Listen(protocol, address)
|
||||
if err != nil {
|
||||
log.Fatalf("%s: %s\n", name, err)
|
||||
}
|
||||
@@ -73,9 +79,15 @@ func main() {
|
||||
|
||||
log.Println("ready")
|
||||
|
||||
if config.Caddy != (ListenConfig{}) {
|
||||
go serveHandler("caddy", config.Caddy, ServeCaddy)
|
||||
go serveHandler("pages", config.Listen.Pages, ServePages)
|
||||
|
||||
if config.Listen.Caddy != "" {
|
||||
go serveHandler("caddy", config.Listen.Caddy, ServeCaddy)
|
||||
}
|
||||
|
||||
serveHandler("pages", config.Pages, ServePages)
|
||||
if config.Listen.Health != "" {
|
||||
go serveHandler("health", config.Listen.Health, ServeHealth)
|
||||
}
|
||||
|
||||
select {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user