๐พ Archived View for source.community โบ ckaznocha โบ gemini โบ blob โบ main โบ status.go captured on 2024-05-26 at 14:52:53. Gemini links have been rewritten to link to archived content
โฌ ๏ธ Previous capture (2024-02-05)
-=-=-=-=-=-=-
. ,-. ,-. . . ,-. ,-. ,-. ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . . `-. | | | | | | |-' | | | | | | | | | | | | | | | | | `-' `-' `-^ ' `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-| /| `-'
git clone https://source.community/ckaznocha/gemini.git
View raw contents of /status.go (main)
โโโโโฎ 1โ //go:generate stringer -linecomment -output status_string.gen.go -type StatusCodeCategory,StatusCode 2โ 3โ package gemini 4โ 5โ const ( 6โ maxCategory = 9 7โ maxCode = 99 8โ codeDivisor = 10 9โ ) 10โ 11โ // StatusCodeCategory identifies a class of Gemini status codes. 12โ type StatusCodeCategory uint8 13โ 14โ // ToCode converts a Categoy to the base code for that category. 15โ func (c StatusCodeCategory) ToCode() StatusCode { 16โ if c > maxCategory { 17โ return 0 18โ } 19โ 20โ return StatusCode(c * codeDivisor) 21โ } 22โ 23โ // The status code categories as defined in `Project Gemini - Speculative 24โ // specification - Section 3.2`. 25โ const ( 26โ StatusCategoryInput StatusCodeCategory = 1 // INPUT 27โ StatusCategorySuccess StatusCodeCategory = 2 // SUCCESS 28โ StatusCategoryRedirect StatusCodeCategory = 3 // REDIRECT 29โ StatusCategoryTemporaryFailure StatusCodeCategory = 4 // TEMPORARY FAILURE 30โ StatusCategoryPermanentFailure StatusCodeCategory = 5 // PERMANENT FAILURE 31โ StatusCategoryClientCertificateRequired StatusCodeCategory = 6 // CLIENT CERTIFICATE REQUIRED 32โ 33โ StatusCategoryUndefined StatusCodeCategory = 0 // UNDEFINED 34โ StatusCategoryUndefinedX StatusCodeCategory = 7 // UNDEFINED 35โ StatusCategoryUndefinedXX StatusCodeCategory = 8 // UNDEFINED 36โ StatusCategoryUndefinedXXX StatusCodeCategory = 9 // UNDEFINED 37โ ) 38โ 39โ // StatusCode represents a Gemini status code. Gemini status codes are two digit 40โ // values. See `Project Gemini - Speculative specification - Section 3.2`. 41โ type StatusCode uint8 42โ 43โ //nolint:gochecknoglobals // un exported lookup table. 44โ var asciiNumbers = [10]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} 45โ 46โ // MarshalText implements the encoding.TextMarshaler interface. It returns the 47โ // the code as an ASCII byte slice. It returns "00" if the code is invalid. 48โ func (c StatusCode) MarshalText() ([]byte, error) { 49โ if c > maxCode { 50โ return []byte{'0', '0'}, nil 51โ } 52โ 53โ return []byte{asciiNumbers[c/codeDivisor], asciiNumbers[c%codeDivisor]}, nil 54โ } 55โ 56โ // ToCategory returns which category the status code belongs to. 57โ func (c StatusCode) ToCategory() StatusCodeCategory { 58โ if c > maxCode { 59โ return StatusCategoryUndefined 60โ } 61โ 62โ return StatusCodeCategory(c / codeDivisor) 63โ } 64โ 65โ // Description returns the description of the code as described in `Project 66โ // Gemini - Speculative specification`. Some but not all of the descriptions may 67โ // be appropriate to return to a client as a failure description. 68โ func (c StatusCode) Description() string { 69โ return statusCodeToText[c] 70โ } 71โ 72โ // The status codes as defined in `Project Gemini - Speculative 73โ // specification - Appendix 1. Full two digit status codes`. 74โ const ( 75โ // 1x - INPUT 76โ StatusInput StatusCode = 10 // INPUT 77โ StatusSensitiveInput StatusCode = 11 // SENSITIVE INPUT 78โ 79โ // 2x - SUCCESS 80โ StatusSuccess StatusCode = 20 // SUCCESS 81โ 82โ // 3x - REDIRECT 83โ StatusTemporaryRedirect StatusCode = 30 // REDIRECT - TEMPORARY 84โ StatusPermanentRedirect StatusCode = 31 // REDIRECT - PERMANENT 85โ 86โ // 4x - TEMPORARY FAILURE 87โ StatusTemporaryFailure StatusCode = 40 // TEMPORARY FAILURE 88โ StatusServerFailure StatusCode = 41 // SERVER UNAVAILABLE 89โ StatusCGIError StatusCode = 42 // CGI ERROR 90โ StatusProxyError StatusCode = 43 // PROXY ERROR 91โ StatusSlowDown StatusCode = 44 // SLOW DOWN 92โ 93โ // 5x - PERMANENT FAILURE 94โ StatusPermanentFailure StatusCode = 50 // PERMANENT FAILURE 95โ StatusNotFound StatusCode = 51 // NOT FOUND 96โ StatusGone StatusCode = 52 // GONE 97โ StatusProxyRequestRefused StatusCode = 53 // PROXY REQUEST REFUSED 98โ StatusBadRequest StatusCode = 59 // BAD REQUEST 99โ 100โ // 6x - CLIENT CERTIFICATE REQUIRED 101โ StatusClientCertificateRequired StatusCode = 60 // CLIENT CERTIFICATE REQUIRED 102โ StatusCertificateNotAuthorised StatusCode = 61 // CERTIFICATE NOT AUTHORIZED 103โ StatusCertificateNotValid StatusCode = 62 // CERTIFICATE NOT VALID 104โ ) 105โ 106โ //nolint:lll,gochecknoglobals // un exported lookup table of very long strings. 107โ var statusCodeToText = map[StatusCode]string{ 108โ // 1x - INPUT 109โ StatusInput: `The requested resource accepts a line of textual user input. The <META> line is a prompt which should be displayed to the user. The same resource should then be requested again with the user's input included as a query component. Queries are included in requests as per the usual generic URL definition in RFC3986, i.e. separated from the path by a ?. Reserved characters used in the user's input must be "percent-encoded" as per RFC3986, and space characters should also be percent-encoded.`, 110โ StatusSensitiveInput: `As per status code 10, but for use with sensitive input such as passwords. Clients should present the prompt as per status code 10, but the user's input should not be echoed to the screen to prevent it being read by "shoulder surfers".`, 111โ 112โ // 2x - SUCCESS 113โ StatusSuccess: `The request was handled successfully and a response body will follow the response header. The <META> line is a MIME media type which applies to the response body.`, 114โ 115โ // 3x - REDIRECT 116โ StatusTemporaryRedirect: `The server is redirecting the client to a new location for the requested resource. There is no response body. <META> is a new URL for the requested resource. The URL may be absolute or relative. The redirect should be considered temporary, i.e. clients should continue to request the resource at the original address and should not performance convenience actions like automatically updating bookmarks. There is no response body.`, 117โ StatusPermanentRedirect: `The requested resource should be consistently requested from the new URL provided in future. Tools like search engine indexers or content aggregators should update their configurations to avoid requesting the old URL, and end-user clients may automatically update bookmarks, etc. Note that clients which only pay attention to the initial digit of status codes will treat this as a temporary redirect. They will still end up at the right place, they just won't be able to make use of the knowledge that this redirect is permanent, so they'll pay a small performance penalty by having to follow the redirect each time.`, 118โ 119โ // 4x - TEMPORARY FAILURE 120โ StatusTemporaryFailure: `The request has failed. There is no response body. The nature of the failure is temporary, i.e. an identical request MAY succeed in the future.`, 121โ StatusServerFailure: `The server is unavailable due to overload or maintenance.`, 122โ StatusCGIError: `A CGI process, or similar system for generating dynamic content, died unexpectedly or timed out.`, 123โ StatusProxyError: `A proxy request failed because the server was unable to successfully complete a transaction with the remote host.)`, 124โ StatusSlowDown: `Rate limiting is in effect.`, 125โ 126โ // 5x - PERMANENT FAILURE 127โ StatusPermanentFailure: `The request has failed. There is no response body. The nature of the failure is permanent, i.e. identical future requests will reliably fail for the same reason.`, 128โ StatusNotFound: `The requested resource could not be found but may be available in the future.`, 129โ StatusGone: `The resource requested is no longer available and will not be available again. Search engines and similar tools should remove this resource from their indices. Content aggregators should stop requesting the resource and convey to their human users that the subscribed resource is gone.`, 130โ StatusProxyRequestRefused: `The request was for a resource at a domain not served by the server and the server does not accept proxy requests.`, 131โ StatusBadRequest: `The server was unable to parse the client's request, presumably due to a malformed request.`, 132โ 133โ // 6x - CLIENT CERTIFICATE REQUIRED 134โ StatusClientCertificateRequired: `The requested resource requires a client certificate to access. If the request was made without a certificate, it should be repeated with one. If the request was made with a certificate, the server did not accept it and the request should be repeated with a different certificate.`, 135โ StatusCertificateNotAuthorised: `The supplied client certificate is not authorized for accessing the particular requested resource. The problem is not with the certificate itself, which may be authorised for other resources.`, 136โ StatusCertificateNotValid: `The supplied client certificate was not accepted because it is not valid. This indicates a problem with the certificate in and of itself, with no consideration of the particular requested resource. The most likely cause is that the certificate's validity start date is in the future or its expiry date has passed, but this code may also indicate an invalid signature, or a violation of a X509 standard requirements.`, 137โ } โโโโโฏ
ยท ยท ยท
ยฉ 2024 source.community