From 23bc5f4fb7542e64c94eaa7fe2c7a6aa55010898 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Sat, 12 Aug 2023 09:40:39 -0600 Subject: move common types to an internal package This helps avoid import cycles. --- internal/types/response.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 internal/types/response.go (limited to 'internal/types/response.go') diff --git a/internal/types/response.go b/internal/types/response.go new file mode 100644 index 0000000..26dda05 --- /dev/null +++ b/internal/types/response.go @@ -0,0 +1,35 @@ +package types + +import "io" + +// Status is the integer status code of a response. +type Status int + +// Response contains the data in a response over the small web. +// +// Because protocols have so many differences, this type represents a +// greatest common denominator of request/response-oriented protocols. +type Response struct { + // Status is the status code of the response. + Status Status + + // Meta contains status-specific additional information. + Meta any + + // Body is the response body, if any. + Body io.Reader +} + +func (response *Response) Close() error { + if cl, ok := response.Body.(io.Closer); ok { + return cl.Close() + } + return nil +} + +// ResponseReader is an object which can serialize a response to a protocol. +type ResponseReader interface { + io.Reader + io.WriterTo + io.Closer +} -- cgit v1.2.3