A golang webfinger server implementation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
573 B

  1. package webfinger
  2. import (
  3. "context"
  4. "net/http"
  5. )
  6. // ErrorKeyType is the type for the context error key
  7. type ErrorKeyType int
  8. // ErrorKey is the key for the context error
  9. var ErrorKey ErrorKeyType
  10. // ErrorFromContext gets the error from the context
  11. func ErrorFromContext(ctx context.Context) error {
  12. v, ok := ctx.Value(ErrorKey).(error)
  13. if !ok {
  14. return nil
  15. }
  16. return v
  17. }
  18. func addError(r *http.Request, err error) *http.Request {
  19. if err == nil {
  20. return r
  21. }
  22. ctx := r.Context()
  23. ctx = context.WithValue(ctx, ErrorKey, err)
  24. r = r.WithContext(ctx)
  25. return r
  26. }