1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package request
- import (
- "context"
- "fmt"
- "log"
- "net/http"
- )
- //Post : retorna um parametro post
- func Post(r *http.Request, parameter string) string {
- if err := r.ParseForm(); err != nil {
- fmt.Printf("ParseForm() err: %v", err)
- return ""
- }
- return r.FormValue(parameter)
- }
- //Get : retorna um parametro get
- func Get(r *http.Request, parameter string) string {
- keys, ok := r.URL.Query()[parameter]
- if !ok || len(keys[0]) < 1 {
- log.Println("Url Param 'key' is missing")
- return ""
- }
- key := keys[0]
- return string(key)
- }
- func SetContextValue(r *http.Request, k string, v interface{}) *http.Request {
- ctx := context.WithValue(r.Context(), k, v)
- return r.WithContext(ctx)
- }
- func GetContextValue(r *http.Request, parameter string) interface{} {
- return r.Context().Value(parameter)
- }
|