On Tue, Dec 22, 2020 at 3:49 AM zilto karamazov <z.karama...@gmail.com> wrote:
>
>
> Hello,
>
> I'm wondering if it is ok to do this ?
>
> ////
> package main
>
> import (
>         "context"
>         "fmt"
>         "log"
>         "net/http"
>
>         "github.com/gorilla/mux"
> )
>
> func main() {
>         addr := "127.0.0.1:8080"
>         r := mux.NewRouter()
>
>         r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
>                 newReq := r.WithContext(context.WithValue(r.Context(), 0, 
> "bla"))
>                 *r = *newReq
>                 // set context
>         })
>
>         r.Use(func(next http.Handler) http.Handler {
>                 return http.HandlerFunc(func(w http.ResponseWriter, r 
> *http.Request) {
>                         next.ServeHTTP(w, r)
>
>                         ctx := r.Context()
>                         v, ok := ctx.Value(0).(string)
>                         if !ok {
>                                 fmt.Println("could not find context value")
>                         } else {
>                                 fmt.Println(v)
>                         }
>                 })
>         })
>
>         s := &http.Server{
>                 Addr:    addr,
>                 Handler: r,
>         }
>
>         if err := s.ListenAndServe(); err != nil && err != 
> http.ErrServerClosed {
>                 log.Fatalf("could not listen on %s : %v", addr, err)
>         }
> }
> ////

What is the goal you are trying to accomplish here?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANODV3%3D_w3cKUSs9nUDNNwSDWDnbFQ2M7fq%2BA2LSq3-jh7vGAQ%40mail.gmail.com.

Reply via email to