galley/galley.go

35 lines
737 B
Go
Raw Normal View History

2025-10-02 17:09:18 -04:00
package main
import (
"log"
"net/http"
2025-10-02 17:09:18 -04:00
"os"
)
func main() {
2025-10-02 22:14:22 -04:00
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
2025-10-03 12:10:08 -04:00
http.HandleFunc("/view/", MakeHandler(ViewHandler))
http.HandleFunc("/edit/", MakeHandler(EditHandler))
http.HandleFunc("/save/", MakeHandler(SaveHandler))
log.Fatal(http.ListenAndServe(":8080", nil))
2025-10-02 17:09:18 -04:00
}
type Page struct {
Title string
Body []byte
2025-10-02 17:09:18 -04:00
}
func (p *Page) save() error {
filename := "data/" + p.Title + ".txt"
2025-10-02 17:09:18 -04:00
return os.WriteFile(filename, p.Body, 0600)
}
func loadPage(title string) (*Page, error) {
filename := "data/" + title + ".txt"
2025-10-02 17:09:18 -04:00
body, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
return &Page{Title: title, Body: body}, nil
}