diff options
author | tjp <tjp@ctrl-c.club> | 2023-11-13 07:25:39 -0700 |
---|---|---|
committer | tjp <tjp@ctrl-c.club> | 2023-11-13 07:27:16 -0700 |
commit | 1e0f8e0aaeaf1bd2ee39c02e922238b641bcf88b (patch) | |
tree | 020e5de91f2343119fed10dede9d2c8262a3cd83 /gemini/protocol.go | |
parent | a808b4692656c10bb43e2d54a2f5ef2746d231d5 (diff) |
refactor contribs to work with a Protocol interface
Diffstat (limited to 'gemini/protocol.go')
-rw-r--r-- | gemini/protocol.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/gemini/protocol.go b/gemini/protocol.go new file mode 100644 index 0000000..e638ec8 --- /dev/null +++ b/gemini/protocol.go @@ -0,0 +1,28 @@ +package gemini + +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 PermanentRedirect(u.String()) } + +func (p proto) TemporaryServerError(err error) *types.Response { return Failure(err) } +func (p proto) PermanentServerError(err error) *types.Response { return PermanentFailure(err) } +func (p proto) CGIFailure(err error) *types.Response { return CGIError(err.Error()) } + +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{} |