This repository has been archived on 2024-01-11. You can view files and clone it, but cannot push or open issues or pull requests.
admin/main.go

58 lines
859 B
Go
Raw Normal View History

2022-01-26 17:00:22 +00:00
package main
import (
"fmt"
"html"
2022-01-26 19:28:26 +00:00
"io/ioutil"
"log"
2022-01-26 17:00:22 +00:00
"net/http"
2022-01-26 19:28:26 +00:00
"gopkg.in/yaml.v3"
2022-01-26 17:00:22 +00:00
)
2022-01-26 19:28:26 +00:00
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
}
2022-01-26 17:00:22 +00:00
func main() {
2022-01-26 19:28:26 +00:00
err := loadConfig()
if err != nil {
log.Fatal("oh no !!!")
}
2022-01-26 17:00:22 +00:00
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
})
2022-01-26 19:28:26 +00:00
err = http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
2022-01-26 17:00:22 +00:00
}