scratch

package module
v0.0.0-...-36c61b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2024 License: MIT Imports: 21 Imported by: 0

README

Scratch

This project can be used to host an online HTML scratch pad.

If you ever missed a "virtual" piece of paper to write a quick idea and have it available from anywhere else with an internet connection, well, this can be it.

It allows you to claim any free page on a it's domain and edit it, saving is done automatically.

You can protect it with a password using the icon in the upper-right corner.


You can also group similar notes under a name, like /groceries, /research. To create a note under it, just access http://domain.tld/examplenamehere/notenamehere. e.g. http://domain.tld/groceries/for-next-week.

To access all the notes under a name, simply access the url without a note name. e.g. http://domain.tld/groceries/. The slash at the end is important here.

Compilation

Make sure you have Go and GNU Make installed. Then do:

$ make all

# creating a static binary with compiled minified assets
$ make ENV=prod all

$ ./bin/scratch

Run

Similarly using GNU make there's a target to directly run the application:

$ make run

It should be available at http://localhost:8097

Documentation

Index

Constants

View Source
const (
	StorageDirName  = "cache"
	KeyFileName     = "key.bin"
	ContentFileName = "content"
)
View Source
const HelpMsg = "Tab indent, Shift+Tab outdent, Ctrl+B bold, Ctrl+I italic, Ctrl+L insert a link, Ctrl+G insert an image"

Variables

This section is empty.

Functions

func RandomURL

func RandomURL(r *http.Request) *url.URL

func RedirectToRandom

func RedirectToRandom(w http.ResponseWriter, r *http.Request)

func Storage

func Storage(base string) storage

Types

type Handler

type Handler struct {
	BasePath storage
	Assets   assets.Map
	// contains filtered or unexported fields
}

func New

func New(storage string) Handler

func (Handler) CheckKey

func (h Handler) CheckKey(r *http.Request) bool

func (*Handler) CheckOrUpdateKeyRequest

func (h *Handler) CheckOrUpdateKeyRequest(r *http.Request) (string, error)

func (Handler) DeleteRequest

func (h Handler) DeleteRequest(r *http.Request) error

func (*Handler) Handle

func (h *Handler) Handle(w http.ResponseWriter, r *http.Request)

func (Handler) ShowIndexForPath

func (h Handler) ShowIndexForPath(p string) ([]byte, error)

func (Handler) ShowRequest

func (h Handler) ShowRequest(path, defTitle string) ([]byte, time.Time, error)

func (Handler) UpdateRequest

func (h Handler) UpdateRequest(r *http.Request) error

type Index

type Index struct {
	Path  string
	Files []IndexEntry
}

type IndexEntry

type IndexEntry struct {
	Path      string
	ModTime   time.Time
	Size      int64
	HasSecret bool
	// contains filtered or unexported fields
}

func (IndexEntry) URL

func (i IndexEntry) URL() template.HTMLAttr

type Page

type Page struct {
	Secret   []byte
	Path     string
	Modified time.Time
	Content  template.HTML
}

func (Page) Help

func (p Page) Help() func() template.HTMLAttr

func (Page) Title

func (p Page) Title(def string) func() template.HTML

Directories

Path Synopsis
cmd
scratch command
internal
assets/cmd command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL