Miki Tebeka avatar Miki Tebeka committed 690536f

Better comments

Comments (0)

Files changed (1)

shortie/shortie.go

 	hitWorkerPath  = "/_worker/hit"
 )
 
-// Encode a number in base62
+// base62Encode encodes a number to a base62 string representation.
 func base62Encode(num uint64) string {
 	if num == 0 {
 		return "0"
 	Count int64
 }
 
-// Get current count of urls
+// getCount return the current count of urls.
 func getCount(ctx appengine.Context) (int64, os.Error) {
 	key := datastore.NewKey(ctx, counterKind, counterKeyName, 0, nil)
 	counter := new(Counter)
 	return counter.Count, nil
 }
 
-// Get next id (short url). We use the global counter and then encode the last count in base62
+/* nextId returns the next short url. 
+We use the global counter and then encode the last count in base62.
+*/
 func nextId(ctx appengine.Context) (string, os.Error) {
 	var count int64
 
 	Hits    int64
 }
 
+// urlKey returns a datastore key for short url.
 func urlKey(ctx appengine.Context, short string) *datastore.Key {
 	return datastore.NewKey(ctx, urlKind, short, 0, nil)
 }
 
+// getURL fetches a URL from the datastore by short url.
 func getURL(ctx appengine.Context, short string) (*URL, os.Error) {
 	key := urlKey(ctx, short)
 	url := new(URL)
 	return url, err
 }
 
-// Increment hit count on url (this is done when short url is resolved)
+// incHits increments hit count on url (this is done when short url is resolved).
 func incHits(ctx appengine.Context, short string) os.Error {
 	return datastore.RunInTransaction(ctx, func(ctx appengine.Context) os.Error {
 		url, err := getURL(ctx, short)
 	}, nil)
 }
 
-// List of user urls, ordered by time (max 1000)
+// userURLs return a list of user urls, ordered by time (max 1000).
 func userURLs(ctx appengine.Context, user string) ([]*URL, os.Error) {
 	query := datastore.NewQuery(urlKind).
 		Filter("User =", user).
 	http.HandleFunc("/", rootHandler)
 }
 
-// Parameters for homeTemplate
+// Parameters for homeTemplate.
 type homeParams struct {
 	User       string
 	LoginTitle string
 	URLs       []*URL
 }
 
-// Add http://<host> suffix to short url. This works both locally and on AppEngine
-func fullUrl(r *http.Request, id string) string {
+/* fullURL adds http://<host> suffix to short url. 
+This works both locally and on AppEngine.
+*/
+func fullURL(r *http.Request, id string) string {
 	return fmt.Sprintf("http://%s/%s", r.Host, id)
 }
 
+// hasSchema check if url has schema prefix.
 func hasSchema(url string) bool {
 	match, _ := regexp.MatchString("^[a-zA-Z]+://", url)
 	return match
 }
 
+// rootHandler handles the main page.
 func rootHandler(w http.ResponseWriter, r *http.Request) {
 	// If it has something, we assume it's a short url
 	if r.URL.Path != "/" {
 		if err != nil {
 			return
 		}
-		params.ShortURL = fullUrl(r, id)
+		params.ShortURL = fullURL(r, id)
 	}
 
 	params.Count, err = getCount(ctx)
 }
 
+/* redirectHandler handles redirects.
+All urls that are not / and worker are assumed to be redirects (short).
+*/
 func redirectHandler(w http.ResponseWriter, r *http.Request) {
 	ctx := appengine.NewContext(r)
 	path := r.URL.Path[1:]
 	http.Redirect(w, r, longURL, http.StatusTemporaryRedirect)
 }
 
-// Format time, used by homeTemplate
+// timeFormatter formats time. It is used by homeTemplate.
 func timeFormatter(args ...interface{}) string {
 	nsec, ok := args[0].(int64)
 	if !ok {
 	return t.Format("2006-01-02 15:04")
 }
 
-// Task handler for updating hits
+// hitHandler is handler for updating hits task.
 func hitHandler(w http.ResponseWriter, r *http.Request) {
 	ctx := appengine.NewContext(r)
 	path := r.FormValue("path")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.