use the config file

This commit is contained in:
leah 2022-01-26 19:28:26 +00:00
parent 667161d876
commit 84932c2449
3 changed files with 45 additions and 2 deletions

2
go.mod
View File

@ -2,4 +2,4 @@ module tildegit.org/southlondon/admin
go 1.17
require gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
require gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b

1
go.sum
View File

@ -1,3 +1,4 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

44
main.go
View File

@ -3,13 +3,55 @@ package main
import (
"fmt"
"html"
"io/ioutil"
"log"
"net/http"
"gopkg.in/yaml.v3"
)
type ServerConfig struct {
Name string
Homepage string
}
type AdminConfig struct {
WebRoot string
}
type AuthConfig struct {
GiteaURL string
AuthorizedUsers []string
}
type Config struct {
Server ServerConfig
Admin AdminConfig
Auth AuthConfig
}
var config = new(Config)
func loadConfig() (err error) {
configfile, err := ioutil.ReadFile("config.yml")
if err != nil {
return err
}
err = yaml.Unmarshal(configfile, &config)
return err
}
func main() {
err := loadConfig()
if err != nil {
log.Fatal("oh no !!!")
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
})
http.ListenAndServe("0.0.0.0:8080", nil)
err = http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}