Created
April 20, 2017 11:35
-
-
Save deankarn/c610086166130d4f5d78ea082916b6c2 to your computer and use it in GitHub Desktop.
decode seo params in pure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/go-playground/pure" | |
mw "github.com/go-playground/pure/examples/middleware/logging-recovery" | |
"github.com/go-playground/pure/middleware" | |
) | |
func main() { | |
mux := pure.New() | |
mux.Use(mw.LoggingAndRecovery(true), middleware.Gzip) | |
mux.Get("/user/:name/:id", user) | |
http.ListenAndServe(":8080", mux.Serve()) | |
} | |
type userParams struct { | |
Name string `form:"name"` | |
ID int `form:"id"` | |
} | |
func user(w http.ResponseWriter, r *http.Request) { | |
var info userParams | |
err := pure.DecodeQueryParams(r, true, &info) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Fprintf(w, "%+v\n", info) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment