Skip to content

Instantly share code, notes, and snippets.

@unders
Last active November 17, 2018 15:45
Show Gist options
  • Select an option

  • Save unders/c8ec1892b6d6a23f5544acc0014b66cc to your computer and use it in GitHub Desktop.

Select an option

Save unders/c8ec1892b6d6a23f5544acc0014b66cc to your computer and use it in GitHub Desktop.

Revisions

  1. unders revised this gist Nov 17, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion simple-go-handler.md
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ type server struct {
    }
    func (s *server) productIndex() http.HandlerFunc {
    func (s *server) product() http.HandlerFunc {
    type getRequest struct {
    Name string
    }
  2. unders revised this gist Nov 17, 2018. 1 changed file with 15 additions and 8 deletions.
    23 changes: 15 additions & 8 deletions simple-go-handler.md
    Original file line number Diff line number Diff line change
    @@ -14,30 +14,37 @@ func productHandler(w http.ResponseWriter, r *http.Request) {

    ```
    type server struct {
    db *someDatabase
    router *someRouter
    container *someContainer
    router *someRouter
    }
    func (s *server) handleSomething() http.HandlerFunc {
    type request struct {
    func (s *server) productIndex() http.HandlerFunc {
    type getRequest struct {
    Name string
    }
    type response struct {
    type getResponse struct {
    Greeting string `json:"greeting"`
    }
    get := func(r *http.Request) () {
    }
    GET /products
    POST /products
    GET /products/10
    PUT /products/10
    return func(w http.ResponseWriter, r *http.Request) {
    key := r.URL.Path[len("/products/"):]
    switch r.Method {
    case "GET":
    // do GET stuff
    data, err := parseGet(r)
    s.container.Get
    case "POST":
    // Fo POST stuff
    default:
    http.Error(w, "Method Not Allowed", 405)
    http.Error(w, s.template.NotAllowed(), 405)
    }
    }
    }
  3. unders revised this gist Nov 17, 2018. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion simple-go-handler.md
    Original file line number Diff line number Diff line change
    @@ -13,15 +13,24 @@ func productHandler(w http.ResponseWriter, r *http.Request) {
    ```

    ```
    type server struct {
    db *someDatabase
    router *someRouter
    }
    func (s *server) handleSomething() http.HandlerFunc {
    type request struct {
    Name string
    }
    type response struct {
    Greeting string `json:"greeting"`
    }
    return func(w http.ResponseWriter, r *http.Request) {
    key := r.URL.Path[len("/products/"):]
    key := r.URL.Path[len("/products/"):]
    switch r.Method {
    case "GET":
    // do GET stuff
  4. unders revised this gist Nov 17, 2018. 1 changed file with 25 additions and 2 deletions.
    27 changes: 25 additions & 2 deletions simple-go-handler.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ````
    ```
    func productHandler(w http.ResponseWriter, r *http.Request) {
    key := r.URL.Path[len("/products/"):]
    switch r.Method {
    @@ -9,4 +9,27 @@ func productHandler(w http.ResponseWriter, r *http.Request) {
    default:
    http.Error(w, "Method Not Allowed", 405)
    }
    }
    }
    ```

    ```
    func (s *server) handleSomething() http.HandlerFunc {
    type request struct {
    Name string
    }
    type response struct {
    Greeting string `json:"greeting"`
    }
    return func(w http.ResponseWriter, r *http.Request) {
    key := r.URL.Path[len("/products/"):]
    switch r.Method {
    case "GET":
    // do GET stuff
    case "POST":
    // Fo POST stuff
    default:
    http.Error(w, "Method Not Allowed", 405)
    }
    }
    }
    ```
  5. unders created this gist Nov 17, 2018.
    12 changes: 12 additions & 0 deletions simple-go-handler.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    ````
    func productHandler(w http.ResponseWriter, r *http.Request) {
    key := r.URL.Path[len("/products/"):]
    switch r.Method {
    case "GET":
    // do GET stuff
    case "POST":
    // Fo POST stuff
    default:
    http.Error(w, "Method Not Allowed", 405)
    }
    }