Refactor routes to use URL params instead of query params

Review Request #7006 — Created March 4, 2015 and submitted

Information

rb-gateway
master
ed1034b...

Reviewers

Previously, routes were of the following format: /file?repo=:repo&id=:id. This isn't very clean and it's not obvious to the reader what it is doing. The design also isn't very RESTful. So the URLs have been refactored to look more closely to the following format: /repos/:repo/file/:id.

The new URLs are as followed:
Getting file blob, checking file existance:
/repos/:repo/file/:id

Getting a file by commit and file path:
/repos/:repo/commits/:commit/path/:path

Getting the path of a repository:
/repos/:repo/path

Getting all branches:
/repos/:repo/branches

Getting all commits
/repos/:repo/branches/:branch/commits
OR /repos/:repo/branches/:branch/commits?start=:start

Getting a commit (includes the diff):
/repos/:repo/commits/:id

Getting the session:
/session

Verified that all new URLs still return the same contents as their old ones.

Description From Last Updated

I think it might be more readable to define this as a table and then add routes in a loop: …

daviddavid
reviewbot
  1. Tool: Pyflakes
    Ignored Files:
        repository.go
        git_repository.go
        README.md
        routes.go
    
    
    
    Tool: PEP8 Style Checker
    Ignored Files:
        repository.go
        git_repository.go
        README.md
        routes.go
    
    
  2. 
      
david
  1. Jessica,

    It looks like this diff has a bunch of changes in it that aren't related to the URLs (and should maybe be in /r/6972/ instead). Can you clean it up?

  2. 
      
JY
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        README.md
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        README.md
        routes.go
    
    
  2. 
      
JY
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        README.md
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        README.md
        routes.go
    
    
  2. 
      
JY
reviewbot
  1. Tool: Pyflakes
    Ignored Files:
        README.md
        routes.go
    
    
    
    Tool: PEP8 Style Checker
    Ignored Files:
        README.md
        routes.go
    
    
  2. 
      
david
  1. 
      
  2. routes.go (Diff revision 4)
     
     
     
     
     
     
     
     
     
     
    Show all issues

    I think it might be more readable to define this as a table and then add routes in a loop:

    routes := map[string]func {
            "/repos/{repo}/file/{id}":                    BasicAuth(getFile),
            "/repos/{repo}/commits/{commit}/path/{path}": BasicAuth(getFileByCommit),
            "/repos/{repo}/path":                         BasicAuth(getPath),
            "/repos/{repo}/branches":                     BasicAuth(getBranches),
            "/repos/{repo}/branches/{branch}/commits":    BasicAuth(getCommits),
            "/repos/{repo}/commits/{id}":                 BasicAuth(getCommit),
            "/session":                                   getSession,
    }
    
    for route, handler := range routes {
            r.HandleFunc(route, handler)
    }
    
  3. 
      
JY
reviewbot
  1. Tool: PEP8 Style Checker
    Ignored Files:
        README.md
        routes.go
    
    
    
    Tool: Pyflakes
    Ignored Files:
        README.md
        routes.go
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
brennie
  1. Ship It!
  2. 
      
JY
Review request changed
Status:
Completed
Change Summary:
Pushed to master (045daab)