๐Ÿ’พ Archived View for source.community โ€บ ckaznocha โ€บ gemini โ€บ blob โ€บ main โ€บ geminitest โ€บ recorder.go captured on 2024-05-10 at 11:18:04. Gemini links have been rewritten to link to archived content

View Raw

More Information

โฌ…๏ธ Previous capture (2024-02-05)

-=-=-=-=-=-=-

                                                         .
,-. ,-. . . ,-. ,-. ,-.    ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . .
`-. | | | | |   |   |-'    |   | | | | | | | | | | | | | |  | |
`-' `-' `-^ '   `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-|
                                                             /|
                                                            `-'

Profile for ckaznocha

ckaznocha / gemini

git clone https://source.community/ckaznocha/gemini.git

Branches

Log

Tree

/geminitest/recorder.go (main)

โ†‘ /geminitest

blob

View raw contents of /geminitest/recorder.go (main)

โ”€โ”€โ”€โ”€โ•ฎ
   1โ”‚ package geminitest
   2โ”‚ 
   3โ”‚ import (
   4โ”‚ 	"bytes"
   5โ”‚ 	"context"
   6โ”‚ 	"io"
   7โ”‚ 
   8โ”‚ 	"source.community/ckaznocha/gemini"
   9โ”‚ )
  10โ”‚ 
  11โ”‚ // ResponseRecorder may be used in test to capture the output of a Handler.
  12โ”‚ type ResponseRecorder struct {
  13โ”‚ 	Body *bytes.Buffer
  14โ”‚ 	Meta string
  15โ”‚ 	Code gemini.StatusCode
  16โ”‚ }
  17โ”‚ 
  18โ”‚ var _ gemini.ResponseWriter = (*ResponseRecorder)(nil)
  19โ”‚ 
  20โ”‚ // NewResponseRecorder returns a response recorder ready to use.
  21โ”‚ func NewResponseRecorder() *ResponseRecorder {
  22โ”‚ 	return &ResponseRecorder{
  23โ”‚ 		Body: bytes.NewBuffer(nil),
  24โ”‚ 	}
  25โ”‚ }
  26โ”‚ 
  27โ”‚ // Failure implements the Failure method of the ResponseWriter interface.
  28โ”‚ func (r *ResponseRecorder) Failure(ctx context.Context, code gemini.StatusCode, msg string) {
  29โ”‚ 	category := code.ToCategory()
  30โ”‚ 	if category < gemini.StatusCategoryTemporaryFailure || category > gemini.StatusCategoryPermanentFailure {
  31โ”‚ 		code = gemini.StatusPermanentFailure
  32โ”‚ 	}
  33โ”‚ 
  34โ”‚ 	r.Code = code
  35โ”‚ 	r.Meta = msg
  36โ”‚ }
  37โ”‚ 
  38โ”‚ // Input implements the Input method of the ResponseWriter interface.
  39โ”‚ func (r *ResponseRecorder) Input(ctx context.Context, prompt string, isSensitive bool) {
  40โ”‚ 	code := gemini.StatusInput
  41โ”‚ 	if isSensitive {
  42โ”‚ 		code = gemini.StatusSensitiveInput
  43โ”‚ 	}
  44โ”‚ 
  45โ”‚ 	r.Code = code
  46โ”‚ 	r.Meta = prompt
  47โ”‚ }
  48โ”‚ 
  49โ”‚ // Redirect implements the Redirect method of the ResponseWriter interface.
  50โ”‚ func (r *ResponseRecorder) Redirect(ctx context.Context, redirectURL string, isPermanant bool) {
  51โ”‚ 	code := gemini.StatusTemporaryRedirect
  52โ”‚ 	if isPermanant {
  53โ”‚ 		code = gemini.StatusPermanentRedirect
  54โ”‚ 	}
  55โ”‚ 
  56โ”‚ 	r.Code = code
  57โ”‚ 	r.Meta = redirectURL
  58โ”‚ }
  59โ”‚ 
  60โ”‚ // Success implements the Success method of the ResponseWriter interface.
  61โ”‚ func (r *ResponseRecorder) Success(ctx context.Context, mimeType string) io.Writer {
  62โ”‚ 	r.Code = gemini.StatusSuccess
  63โ”‚ 	r.Meta = mimeType
  64โ”‚ 
  65โ”‚ 	return r.Body
  66โ”‚ }
โ”€โ”€โ”€โ”€โ•ฏ

ยท ยท ยท

๐Ÿก Home

FAQs

Privacy Policy

Terms & Conditions

Official Gemlog

info@source.community

ยฉ 2024 source.community