William Wiechorek 6 years ago
parent
commit
6fb4dc6849
3 changed files with 5 additions and 0 deletions
  1. BIN
      build
  2. 4 0
      main.go
  3. 1 0
      src/controller/Test/Test.go

BIN
build


+ 4 - 0
main.go

1
 package main
1
 package main
2
 
2
 
3
 import (
3
 import (
4
+	"context"
4
 	"log"
5
 	"log"
5
 	"net/http"
6
 	"net/http"
6
 	"strconv"
7
 	"strconv"
20
 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
21
 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
21
 		var Errors errorHandler.Errors
22
 		var Errors errorHandler.Errors
22
 
23
 
24
+		ctx := context.WithValue(r.Context(), "Username", "William")
25
+		r.WithContext(ctx)
26
+
23
 		res.SetResponseWriter(w)
27
 		res.SetResponseWriter(w)
24
 		req.SetRequest(r)
28
 		req.SetRequest(r)
25
 
29
 

+ 1 - 0
src/controller/Test/Test.go

18
 
18
 
19
 //Inicial : Func
19
 //Inicial : Func
20
 func Inicial(w http.ResponseWriter, r *http.Request, vars []string) {
20
 func Inicial(w http.ResponseWriter, r *http.Request, vars []string) {
21
+	fmt.Print(r.Context().Value("Username").(string))
21
 	var Errors errorHandler.Errors
22
 	var Errors errorHandler.Errors
22
 
23
 
23
 	user, err := auth.GetUser(r)
24
 	user, err := auth.GetUser(r)