If the previous owner of a link no longer appears in the tailnet users,
any user can overwrite the link and will become the new owner.
Change-Id: I52bbc5e906ff5b1b6424c0e320fd0d02c006ac12
store click stats in db. Hold stats in memory and flush to db every
minute, as well as whenever the /_/export endpoint is called.
Change DB.List() to DB.LoadAll(), since it practice we actually want
the data, not just the names.
Change-Id: I21a3aa19bfc065d595822f004a14b96bbb347de8
after successfully saving a golink, return an HTML response only if the
request indicates it can accept text/html, otherwise return JSON. This
allows for a very simple API:
% curl -d short=foo -d long=http://foo.com/ go
{"Short":"foo","Long":"http://foo.com/" ... }
Change-Id: I32e9c028207c5c7b8741d7dd31ebed35cf38a1de
append "+" to the end of a golink to get information about the link
rather than being redirected. For now, this just pretty prints the raw
JSON. We could make it prettier later.
Change-Id: If25c9f61c326f6e12cdec89b78eb3ca1b741a0ef
This is a straight refactor with no functional changes. All file access
is captured in the FileDB type. The DB interface is not strictly
necessary here since we only have a single implementation, but helped to
keep the API clean, which will be useful in a future sqlite migration.
Change-Id: I9b86db3040e2618a4ffef237369288ccfc10bc1e
This sets up an embed.FS even though we only have the one file right
now, as we will have more shortly.
Change-Id: I1292e4c00602fbfc3a7bc2a5f93a8c9b9e6715c0
Otherwise we can't save a link using the funcs.
Change-Id: If48e1527f5b21f0314d3e1b4c3c38b9ca7fa65b8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
long URLs are now executed using text/template to allow for more advaned
handling. Templates have access to PathEscape and QueryEscape funcs, as
well as a data struct containing the current time (Now) and the
remaining path from the user-provided short link (Path).
Change-Id: Iedbbafccf98c4a623d06e9519877c7137ca559e8
- ignore hyphens, preventing link ambiguity. If hyphens are included
when creating the link, they are saved as the "canonical" name for
the link, but links are still resolved without them.
- allow overwriting the "canonical" name for a short link by simply
recreating it with the new canonical name. Stats are not updated when
the canonical name is updated, which is probably fine.
Change-Id: Ia962caa846489850784ef15cdfad7f13bafd8842
In the meantime, before sqlite-and-litestream-to-S3, and as a
transition mechanism to move this service to be running on Fly instead
of Brad's dev box, add support for backing up the go/ links to a file
in git, baking it into the binary, and restoring it as needed when the
binary starts up, including in a newly added dev mode.
Change-Id: I8961f720c0f9b29eb7b0b6b1f62bac7ace2d67dc