all repos — todo.txt-web @ 444af8de3198d8a4fe86de9e24c8c4dcac920ee4

Minimalist Web interface for todo.txt file management

Remove TLS, fix embed
Tim Izzo tim@5ika.ch
Mon, 21 Jul 2025 17:56:06 +0200
commit

444af8de3198d8a4fe86de9e24c8c4dcac920ee4

parent

43d313673f4a4ba7890455ba05026ad807d9e7b3

3 files changed, 7 insertions(+), 45 deletions(-)

jump to
M config.goconfig.go

@@ -1,8 +1,6 @@

package main import ( - "crypto/tls" - "crypto/x509" "os" "github.com/charmbracelet/log"

@@ -10,14 +8,6 @@ "gopkg.in/yaml.v3"

) type Config struct { - Server struct { - CertFilePath string `yaml:"certFilePath"` - KeyFilePath string `yaml:"keyFilePath"` - } `yaml:"server"` - Client struct { - CACertFilePath string `yaml:"cACertFilePath"` - } `yaml:"client"` - TodoPath string `yaml:"todoPath"` }

@@ -31,25 +21,3 @@ var cfg Config

yaml.Unmarshal(configFile, &cfg) return cfg } - -func getTLSConfig(config Config) *tls.Config { - - serverTLSCert, err := tls.LoadX509KeyPair(config.Server.CertFilePath, config.Server.KeyFilePath) - if err != nil { - log.Fatalf("error opening certificate and key file for control connection. Error %v", err) - return nil - } - - certPool := x509.NewCertPool() - if caCertPEM, err := os.ReadFile(config.Client.CACertFilePath); err != nil { - panic(err) - } else if ok := certPool.AppendCertsFromPEM(caCertPEM); !ok { - panic("invalid cert in CA PEM") - } - - return &tls.Config{ - ClientAuth: tls.RequireAndVerifyClientCert, - ClientCAs: certPool, - Certificates: []tls.Certificate{serverTLSCert}, - } -}
M main.gomain.go

@@ -2,7 +2,6 @@ package main

import ( "embed" - "flag" "html/template" "net/http" "strconv"

@@ -17,27 +16,22 @@ //go:embed static/* templates/*

var fs embed.FS func main() { - configPath := flag.String("config", "config.yaml", "Path to config file") - flag.Parse() - config := getConfig(*configPath) + // TODO Use config for todo path + // configPath := flag.String("config", "config.yaml", "Path to config file") + // flag.Parse() + // config := getConfig(*configPath) router := gin.Default() templ := template.Must(template.New("").ParseFS(fs, "templates/*.html")) router.SetHTMLTemplate(templ) - router.StaticFS("/static", http.FS(fs)) + router.StaticFS("/public", http.FS(fs)) router.GET("/", loadTasksList) router.POST("/", loadTasksList) - server := http.Server{ - Addr: ":4443", - Handler: router, - TLSConfig: getTLSConfig(config), - } - defer server.Close() - log.Fatal(server.ListenAndServeTLS("", "")) + router.Run() } func loadTasksList(c *gin.Context) {
M templates/layout.htmltemplates/layout.html

@@ -5,7 +5,7 @@ <head>

<meta charset="UTF-8" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <title>{{block "title" .}}todo.txt{{end}}</title> - <link rel="stylesheet" type="text/css" href="/static/style.css" /> + <link rel="stylesheet" type="text/css" href="/public/static/style.css" /> </head> <body> {{block "content" .}}{{end}}