This repository has been archived on 2022-11-27. You can view files and clone it, but cannot push or open issues or pull requests.
activitypub/client/internal.go
Marius Orcsik c3a38f35e7
Holy shit! Merged the activitystreams repo
Only 3 tests failing
2019-12-03 17:23:59 +01:00

35 lines
1,015 B
Go

package client
import (
"bytes"
"fmt"
"net/http"
)
// ErrorHandlerFunc is a data type for the default ErrorHandler function of the package
type ErrorHandlerFunc func(...error) http.HandlerFunc
// ErrorHandler is the error handler callback for the ActivityPub package.
// It can be overloaded from the packages that require it
var ErrorHandler ErrorHandlerFunc = func(errors ...error) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
output := bytes.Buffer{}
for i, e := range errors {
output.WriteString(fmt.Sprintf("#%d %s\n", i, e.Error()))
}
w.WriteHeader(http.StatusInternalServerError)
w.Header().Add("Content-Type", "text/plain")
w.Write(output.Bytes())
}
}
// Routes
// {actor}/ -> HandleActorGET (requires LoadActorMiddleware(r, w), HandleError(r, w))
// {actor}/{inbox} -> HandleActorInboxGET
// {actor}/{outbox} -> HandleActorOutboxGET
// S2S
// {actor}/inbox -> InboxRequest (requires LoadActorMIddleware(r, w))
// C2S
// {actor}/outbox -> OutboxRequest