diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-08-12 09:40:39 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-08-12 09:40:39 -0600 |
commit | 23bc5f4fb7542e64c94eaa7fe2c7a6aa55010898 (patch) | |
tree | ec8113d3aa2379e3ca9cb3c6e13a5531895ea8c0 /spartan/response.go | |
parent | 57a31a9b2cd549174d839b9b91b47db337f174cc (diff) |
move common types to an internal package
This helps avoid import cycles.
Diffstat (limited to 'spartan/response.go')
-rw-r--r-- | spartan/response.go | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/spartan/response.go b/spartan/response.go index aeddd68..df565f9 100644 --- a/spartan/response.go +++ b/spartan/response.go @@ -8,20 +8,20 @@ import ( "strconv" "sync" - sr "tildegit.org/tjp/sliderule" + "tildegit.org/tjp/sliderule/internal/types" ) // The spartan response types. const ( - StatusSuccess sr.Status = 2 - StatusRedirect sr.Status = 3 - StatusClientError sr.Status = 4 - StatusServerError sr.Status = 5 + StatusSuccess types.Status = 2 + StatusRedirect types.Status = 3 + StatusClientError types.Status = 4 + StatusServerError types.Status = 5 ) // Success builds a successful spartan response. -func Success(mediatype string, body io.Reader) *sr.Response { - return &sr.Response{ +func Success(mediatype string, body io.Reader) *types.Response { + return &types.Response{ Status: StatusSuccess, Meta: mediatype, Body: body, @@ -29,24 +29,24 @@ func Success(mediatype string, body io.Reader) *sr.Response { } // Redirect builds a spartan redirect response. -func Redirect(url string) *sr.Response { - return &sr.Response{ +func Redirect(url string) *types.Response { + return &types.Response{ Status: StatusRedirect, Meta: url, } } // ClientError builds a "client error" spartan response. -func ClientError(err error) *sr.Response { - return &sr.Response{ +func ClientError(err error) *types.Response { + return &types.Response{ Status: StatusClientError, Meta: err.Error(), } } // ServerError builds a "server error" spartan response. -func ServerError(err error) *sr.Response { - return &sr.Response{ +func ServerError(err error) *types.Response { + return &types.Response{ Status: StatusServerError, Meta: err.Error(), } @@ -58,7 +58,7 @@ var InvalidResponseHeaderLine = errors.New("Invalid response header line.") // InvalidResponseLineEnding indicates that a spartan response header didn't end with "\r\n". var InvalidResponseLineEnding = errors.New("Invalid response line ending.") -func ParseResponse(rdr io.Reader) (*sr.Response, error) { +func ParseResponse(rdr io.Reader) (*types.Response, error) { bufrdr := bufio.NewReader(rdr) hdrLine, err := bufrdr.ReadString('\n') @@ -74,15 +74,15 @@ func ParseResponse(rdr io.Reader) (*sr.Response, error) { return nil, InvalidResponseHeaderLine } - return &sr.Response{ - Status: sr.Status(status), + return &types.Response{ + Status: types.Status(status), Meta: hdrLine[2 : len(hdrLine)-2], Body: bufrdr, }, nil } // NewResponseReader builds a reader for a response. -func NewResponseReader(response *sr.Response) sr.ResponseReader { +func NewResponseReader(response *types.Response) types.ResponseReader { return &responseReader{ Response: response, once: &sync.Once{}, @@ -90,7 +90,7 @@ func NewResponseReader(response *sr.Response) sr.ResponseReader { } type responseReader struct { - *sr.Response + *types.Response reader io.Reader once *sync.Once } |