Skip to content

Commit

Permalink
update struct names and home page
Browse files Browse the repository at this point in the history
  • Loading branch information
mco-gh committed May 18, 2020
1 parent 0fc385e commit f2d5c1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 5 additions & 3 deletions home.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ <h1><font face="courier">mco.fyi</font> - Marc's short link service</h1>
<div class="row">
<div class="four columns">
<img height="300" width="250" src="/img/meiko.jpg" />
<br>
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 <a src="https://github.com/marcacohen/mco.fyi">Github</a>. Also, here's a <a src="https://mco.fyi/links">slide deck</a> and a <a src="https://mco.fyi/links">blog article</a> about this service.
</div>
<div class="eight columns">
<table width="100%">
Expand All @@ -69,9 +71,9 @@ <h1><font face="courier">mco.fyi</font> - Marc's short link service</h1>
<tbody>
{{ range . }}
<tr>
<td>{{.C}}</td>
<td><a href={{.K}}>mco.fyi/{{.K}}</a></td>
<td>{{.D}}</td>
<td>{{.Count}}</td>
<td><a href={{.Url}}>mco.fyi/{{.Key}}</a></td>
<td>{{.Desc}}</td>
</tr>
{{ end }}
</tbody>
Expand Down
15 changes: 10 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f2d5c1b

Please sign in to comment.