From 1e0f8e0aaeaf1bd2ee39c02e922238b641bcf88b Mon Sep 17 00:00:00 2001 From: tjp Date: Mon, 13 Nov 2023 07:25:39 -0700 Subject: refactor contribs to work with a Protocol interface --- spartan/protocol.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spartan/protocol.go (limited to 'spartan/protocol.go') diff --git a/spartan/protocol.go b/spartan/protocol.go new file mode 100644 index 0000000..8e94857 --- /dev/null +++ b/spartan/protocol.go @@ -0,0 +1,26 @@ +package spartan + +import ( + "io" + "net/url" + + "tildegit.org/tjp/sliderule/internal" + "tildegit.org/tjp/sliderule/internal/types" +) + +type proto struct{} + +func (p proto) TemporaryRedirect(u *url.URL) *types.Response { return Redirect(u.String()) } +func (p proto) PermanentRedirect(u *url.URL) *types.Response { return Redirect(u.String()) } + +func (p proto) TemporaryServerError(err error) *types.Response { return ServerError(err) } +func (p proto) PermanentServerError(err error) *types.Response { return ServerError(err) } +func (p proto) CGIFailure(err error) *types.Response { return ServerError(err) } + +func (p proto) Success(filename string, body io.Reader) *types.Response { + return Success(internal.MediaType(filename), body) +} + +func (p proto) ParseResponse(input io.Reader) (*types.Response, error) { return ParseResponse(input) } + +var ServerProtocol types.ServerProtocol = proto{} -- cgit v1.2.3