A golang webfinger server implementation
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

32 řádky
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. }