diff --git a/home.html b/home.html index f3ef5fb..dda6d2e 100644 --- a/home.html +++ b/home.html @@ -56,6 +56,8 @@

mco.fyi - Marc's short link service

+
+This is Meiko. Whenever you visit one of my short links, his job is to go fetch the long version and return it to your browser. Thanks to Google and Meiko, mco.fyi is fast and reliable. If you'd like to try this code for yourself, it's available on Github. Also, here's a slide deck and a blog article about this service.
@@ -69,9 +71,9 @@

mco.fyi - Marc's short link service

{{ range . }} - - - + + + {{ end }} diff --git a/main.go b/main.go index 6d43ee2..a8a31c2 100644 --- a/main.go +++ b/main.go @@ -27,11 +27,12 @@ import ( var linkdata map[string]interface{} var doc *firestore.DocumentRef +// key/value structure for short link data type kv struct { - K string - C int64 - U string - D string + Key string // short name + Count int64 // count + Url string // URL + Desc string // description } func redirect(w http.ResponseWriter, r *http.Request) { @@ -56,7 +57,7 @@ func redirect(w http.ResponseWriter, r *http.Request) { kvs = append(kvs, kv{k, count, desturl, desc}) } sort.Slice(kvs, func(i, j int) bool { - return kvs[i].C > kvs[j].C + return kvs[i].Count > kvs[j].Count }) err = t.Execute(w, kvs) if err != nil { @@ -98,6 +99,10 @@ func main() { } linkdata = docsnap.Data() + // This function runs in the background. It gets notified + // anytime the dataset changes, and reloads the local copy + // in response to those notifications so that the running + // instance always has the latest version of the data handy. go func() { iter := doc.Snapshots(ctx) defer iter.Stop()
{{.C}}mco.fyi/{{.K}}{{.D}}{{.Count}}mco.fyi/{{.Key}}{{.Desc}}