Code Monkey home page Code Monkey logo

feedback's Introduction

Feedback

This is a rails inspired golang framework that uses Hacker News style article submission, comments, and voting.

This repo is also a framework you can fork and turn into your own app.

Our sample app is live at RemoteRenters

func handleContext(c *Context) {
  tokens := c.tokens

  if len(tokens) == 3 { //          /foo/
    handlePathContext(c, tokens[1], "", "")
  } else if len(tokens) == 4 { //   /foo/bar/
    handlePathContext(c, tokens[1], tokens[2], "")
  } else if len(tokens) == 5 { //   /foo/bar/more/
    handlePathContext(c, tokens[1], tokens[2], tokens[3])
  } else {
    c.notFound = true
  }
}

This is the heart of the routing code. You can have three levels of:

/foo/

/foo/bar/

/foo/bar/more/

func handlePathContext(c *Context, first, second, third string) {
  if first == "models" {
    handleModels(c, second, third)
  } else if first == "sessions" {
    handleSessions(c, second, third)
  } else if first == "stories" {
    handleStories(c, second, third)
  } else if first == "users" {
    handleUsers(c, second, third)
  } else if first == "comments" {
    handleComments(c, second, third)
  } else if first == "about" {
    handleAbout(c, second, third)
  } else if first == "fresh" {
    handleFresh(c, second, third)
  } else {
    c.notFound = true
  }
}

Each main section calls it's controller's handle method with second and third.

Second might be "" if it's just /foo/ Third will also be "" Second will be "something" if it's /foo/something/ And third will only not be "" if you have all three parts.

feedback's People

Contributors

andrewarrow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.