35 lines
737 B
Go
35 lines
737 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
|
http.HandleFunc("/view/", MakeHandler(ViewHandler))
|
|
http.HandleFunc("/edit/", MakeHandler(EditHandler))
|
|
http.HandleFunc("/save/", MakeHandler(SaveHandler))
|
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
|
}
|
|
|
|
type Page struct {
|
|
Title string
|
|
Body []byte
|
|
}
|
|
|
|
func (p *Page) save() error {
|
|
filename := "data/" + p.Title + ".txt"
|
|
return os.WriteFile(filename, p.Body, 0600)
|
|
}
|
|
|
|
func loadPage(title string) (*Page, error) {
|
|
filename := "data/" + title + ".txt"
|
|
body, err := os.ReadFile(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Page{Title: title, Body: body}, nil
|
|
}
|