a bit of renaming things

This commit is contained in:
2017-08-09 16:40:41 -07:00
parent c63022b636
commit da848ae87f
7 changed files with 28 additions and 29 deletions
+9 -10
View File
@@ -13,14 +13,14 @@ import (
"git.stephensearles.com/stephen/acedoc"
)
type docref struct {
type editSession struct {
clients uint
name string
doc *acedoc.Document
tmpdir string
}
func (ch *CaddyHugo) newClient(docName string) (*docref, error) {
func (ch *CaddyHugo) newEditSession(docName string) (*editSession, error) {
filename := ch.docFilename(docName)
fmt.Println("opening", filename)
@@ -32,7 +32,7 @@ func (ch *CaddyHugo) newClient(docName string) (*docref, error) {
draftPrefix := fmt.Sprintf("draft-%s", base64.RawURLEncoding.EncodeToString([]byte(docName)))
tmpdir := path.Join(os.TempDir(), draftPrefix)
ref := &docref{
ref := &editSession{
name: docName,
doc: acedoc.NewString(string(contents)),
tmpdir: tmpdir,
@@ -103,26 +103,25 @@ func (ch *CaddyHugo) newClient(docName string) (*docref, error) {
return ref, nil
}
func (ch *CaddyHugo) hasdocref(docName string) (*docref, bool) {
func (ch *CaddyHugo) hasEditSession(docName string) (*editSession, bool) {
dr, ok := ch.docs[ch.docFilename(docName)]
return dr, ok
}
func (ch *CaddyHugo) client(docName string) (*docref, error) {
func (ch *CaddyHugo) editSession(docName string) (*editSession, error) {
ch.mtx.Lock()
defer ch.mtx.Unlock()
var err error
dr, ok := ch.hasdocref(docName)
dr, ok := ch.hasEditSession(docName)
if !ok {
dr, err = ch.newClient(docName)
dr, err = ch.newEditSession(docName)
}
return dr, err
}
func (ch *CaddyHugo) doc(r *http.Request) (*docref, error) {
name := r.URL.Path[len("/hugo/edit/"):]
return ch.client(name)
func docNameFromEditRequest(r *http.Request) string {
return r.URL.Path[len("/hugo/edit/"):]
}