Advertisement
Guest User

Untitled

a guest
Sep 17th, 2023
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "net/http"
  6. )
  7.  
  8. var AnonymousUser = "Anonymous"
  9.  
  10. func main() {
  11.  
  12. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  13. w.Write([]byte("Request Received From: "))
  14.  
  15. user := r.Header["X-User-Id"]
  16.  
  17. fmt.Println("User: ", user)
  18.  
  19. if len(user) == 0 {
  20. w.Write([]byte(AnonymousUser))
  21. } else {
  22. w.Write([]byte(user[0]))
  23. }
  24.  
  25. w.Write([]byte("\n"))
  26. })
  27.  
  28. fmt.Println("Listening on port 8081")
  29. http.ListenAndServe(":8081", nil)
  30.  
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement