William Wiechorek 6 年之前
父节点
当前提交
6fb4dc6849
共有 3 个文件被更改,包括 5 次插入0 次删除
  1. 二进制
      build
  2. 4 0
      main.go
  3. 1 0
      src/controller/Test/Test.go

二进制
build


+ 4 - 0
main.go

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

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

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