Move errors to gemini.go

This commit is contained in:
adnano 2020-10-13 20:10:04 -04:00
parent 2c1081966d
commit 4189a4f717
4 changed files with 13 additions and 23 deletions

View File

@ -4,21 +4,12 @@ import (
"bufio" "bufio"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors"
"io/ioutil" "io/ioutil"
"net" "net"
"net/url" "net/url"
"strconv" "strconv"
) )
// Client errors.
var (
ErrInvalidURL = errors.New("gemini: invalid URL")
ErrInvalidResponse = errors.New("gemini: invalid response")
ErrCertificateUnknown = errors.New("gemini: unknown certificate")
ErrCertificateNotTrusted = errors.New("gemini: certificate is not trusted")
)
// Request represents a Gemini request. // Request represents a Gemini request.
type Request struct { type Request struct {
// URL specifies the URL being requested. // URL specifies the URL being requested.

6
fs.go
View File

@ -1,7 +1,6 @@
package gmi package gmi
import ( import (
"errors"
"io" "io"
"mime" "mime"
"os" "os"
@ -15,11 +14,6 @@ func init() {
mime.AddExtensionType(".gemini", "text/gemini") mime.AddExtensionType(".gemini", "text/gemini")
} }
// FileServer errors.
var (
ErrNotAFile = errors.New("gemini: not a file")
)
// FileServer takes a filesystem and returns a Handler which uses that filesystem. // FileServer takes a filesystem and returns a Handler which uses that filesystem.
// The returned Handler sanitizes paths before handling them. // The returned Handler sanitizes paths before handling them.
func FileServer(fsys FS) Handler { func FileServer(fsys FS) Handler {

View File

@ -3,6 +3,7 @@ package gmi
import ( import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors"
"sync" "sync"
"time" "time"
) )
@ -39,10 +40,21 @@ const (
StatusClassCertificateRequired = 6 StatusClassCertificateRequired = 6
) )
// Errors.
var (
ErrInvalidURL = errors.New("gmi: invalid URL")
ErrInvalidResponse = errors.New("gmi: invalid response")
ErrCertificateUnknown = errors.New("gmi: unknown certificate")
ErrCertificateExpired = errors.New("gmi: certificate expired")
ErrCertificateNotTrusted = errors.New("gmi: certificate is not trusted")
ErrNotAFile = errors.New("gmi: not a file")
ErrBodyNotAllowed = errors.New("gmi: response status code does not allow for body")
)
// DefaultClient is the default client. It is used by Send. // DefaultClient is the default client. It is used by Send.
// //
// On the first request, DefaultClient will load the default list of known hosts. // On the first request, DefaultClient will load the default list of known hosts.
var DefaultClient = &Client{} var DefaultClient Client
var ( var (
crlf = []byte("\r\n") crlf = []byte("\r\n")

View File

@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors"
"log" "log"
"net" "net"
"net/url" "net/url"
@ -16,12 +15,6 @@ import (
"time" "time"
) )
// Server errors.
var (
ErrBodyNotAllowed = errors.New("gemini: response status code does not allow for body")
ErrCertificateExpired = errors.New("gemini: certificate expired")
)
// Server is a Gemini server. // Server is a Gemini server.
type Server struct { type Server struct {
// Addr specifies the address that the server should listen on. // Addr specifies the address that the server should listen on.