serve frontend from go
This commit is contained in:
		
							
								
								
									
										22
									
								
								internal/auth/ctx.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								internal/auth/ctx.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| package auth | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"net/http" | ||||
| ) | ||||
|  | ||||
| type authkey int | ||||
|  | ||||
| const keyClaims = iota | ||||
|  | ||||
| func writeToContext(r *http.Request, claims *Claims) *http.Request { | ||||
| 	ctx := context.WithValue(r.Context(), keyClaims, claims) | ||||
| 	return r.WithContext(ctx) | ||||
| } | ||||
|  | ||||
| // ExtractClaims extracts user claims from given context. If no claims in context ok = false. | ||||
| func ExtractClaims(ctx context.Context) (claims *Claims, ok bool) { | ||||
| 	val := ctx.Value(keyClaims) | ||||
| 	claims, ok = val.(*Claims) | ||||
| 	return | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 u80864958
					u80864958