greatape/components/api/handlers/post_to_outbox_handler.go

46 wiersze
1001 B
Go

package handlers
import (
"net/http"
. "github.com/reiver/greatape/components/api/protobuf"
. "github.com/reiver/greatape/components/contracts"
. "github.com/xeronith/diamante/contracts/network/http"
pipeline "github.com/xeronith/diamante/network/http"
)
type postToOutboxHandler struct {
}
func PostToOutboxHandler() IHttpHandler {
return &postToOutboxHandler{}
}
func (handler *postToOutboxHandler) Method() string {
return http.MethodPost
}
func (handler *postToOutboxHandler) Path() string {
return "/u/:username/outbox"
}
func (handler *postToOutboxHandler) HandlerFunc() HttpHandlerFunc {
return func(x IServerDispatcher) error {
request := &PostToOutboxRequest{}
result := &PostToOutboxResult{}
onRequestUnmarshalled := func(request *PostToOutboxRequest) {
request.Username = x.Param("username")
}
return pipeline.Handle(x,
"post_to_outbox",
POST_TO_OUTBOX_REQUEST,
POST_TO_OUTBOX_RESULT,
request, result,
onRequestUnmarshalled,
false,
)
}
}