Rename repository to go-gemini

This commit is contained in:
Adnan Maolood 2020-10-24 15:15:32 -04:00
parent 1634c2c11c
commit f0345f3495
18 changed files with 45 additions and 45 deletions

View File

@ -1,4 +1,4 @@
gmi is available under the terms of the MIT license:
go-gemini is available under the terms of the MIT license:
Copyright (c) 2020 Adnan Maolood

View File

@ -1,8 +1,8 @@
# gmi
# go-gemini
[![GoDoc](https://godoc.org/git.sr.ht/~adnano/gmi?status.svg)](https://godoc.org/git.sr.ht/~adnano/gmi)
Package `gmi` implements the [Gemini protocol](https://gemini.circumlunar.space) in Go.
Package gemini implements the [Gemini protocol](https://gemini.circumlunar.space) in Go.
It aims to provide an API similar to that of `net/http` to make it easy to develop Gemini clients and servers.

View File

@ -1,4 +1,4 @@
package gmi
package gemini
import (
"crypto"

View File

@ -1,4 +1,4 @@
package gmi
package gemini
import (
"bufio"

24
doc.go
View File

@ -1,10 +1,10 @@
/*
Package gmi implements the Gemini protocol.
Package gemini implements the Gemini protocol.
Send makes a Gemini request with the default client:
req := gmi.NewRequest("gemini://example.com")
resp, err := gmi.Send(req)
req := gemini.NewRequest("gemini://example.com")
resp, err := gemini.Send(req)
if err != nil {
// handle error
}
@ -12,7 +12,7 @@ Send makes a Gemini request with the default client:
For control over client behavior, create a custom Client:
var client gmi.Client
var client gemini.Client
resp, err := client.Send(req)
if err != nil {
// handle error
@ -29,20 +29,20 @@ Custom clients can load their own list of known hosts:
Clients can control when to trust certificates with TrustCertificate:
client.TrustCertificate = func(hostname string, cert *x509.Certificate, knownHosts *gmi.KnownHosts) error {
client.TrustCertificate = func(hostname string, cert *x509.Certificate, knownHosts *gemini.KnownHosts) error {
return knownHosts.Lookup(hostname, cert)
}
If a server responds with StatusCertificateRequired, the default client will generate a certificate and resend the request with it. Custom clients can do so in GetCertificate:
client.GetCertificate = func(hostname string, store *gmi.CertificateStore) *tls.Certificate {
client.GetCertificate = func(hostname string, store *gemini.CertificateStore) *tls.Certificate {
// If the certificate is in the store, return it
if cert, err := store.Lookup(hostname); err == nil {
return &cert
}
// Otherwise, generate a certificate
duration := time.Hour
cert, err := gmi.NewCertificate(hostname, duration)
cert, err := gemini.NewCertificate(hostname, duration)
if err != nil {
return nil
}
@ -53,7 +53,7 @@ If a server responds with StatusCertificateRequired, the default client will gen
Server is a Gemini server.
var server gmi.Server
var server gemini.Server
Servers must be configured with certificates:
@ -64,13 +64,13 @@ Servers must be configured with certificates:
Servers can accept requests for multiple hosts and schemes:
server.RegisterFunc("example.com", func(w *gmi.ResponseWriter, r *gmi.Request) {
server.RegisterFunc("example.com", func(w *gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprint(w, "Welcome to example.com")
})
server.RegisterFunc("example.org", func(w *gmi.ResponseWriter, r *gmi.Request) {
server.RegisterFunc("example.org", func(w *gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprint(w, "Welcome to example.org")
})
server.RegisterFunc("http://example.net", func(w *gmi.ResponseWriter, r *gmi.Request) {
server.RegisterFunc("http://example.net", func(w *gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprint(w, "Proxied content from http://example.net")
})
@ -81,4 +81,4 @@ To start the server, call ListenAndServe:
// handle error
}
*/
package gmi
package gemini

View File

@ -7,7 +7,7 @@ import (
"fmt"
"log"
"git.sr.ht/~adnano/gmi"
gmi "git.sr.ht/~adnano/go-gemini"
)
type user struct {

View File

@ -11,7 +11,7 @@ import (
"os"
"time"
"git.sr.ht/~adnano/gmi"
gmi "git.sr.ht/~adnano/go-gemini"
)
func main() {

View File

@ -10,7 +10,7 @@ import (
"os"
"time"
"git.sr.ht/~adnano/gmi"
gmi "git.sr.ht/~adnano/go-gemini"
)
var (

View File

@ -11,7 +11,7 @@ import (
"os"
"time"
"git.sr.ht/~adnano/gmi"
gmi "git.sr.ht/~adnano/go-gemini"
)
func main() {

2
fs.go
View File

@ -1,4 +1,4 @@
package gmi
package gemini
import (
"io"

View File

@ -1,4 +1,4 @@
package gmi
package gemini
import (
"crypto/tls"
@ -42,13 +42,13 @@ const (
// 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")
ErrInvalidURL = errors.New("gemini: invalid URL")
ErrInvalidResponse = errors.New("gemini: invalid response")
ErrCertificateUnknown = errors.New("gemini: unknown certificate")
ErrCertificateExpired = errors.New("gemini: certificate expired")
ErrCertificateNotTrusted = errors.New("gemini: certificate is not trusted")
ErrNotAFile = errors.New("gemini: not a file")
ErrBodyNotAllowed = errors.New("gemini: response status code does not allow for body")
)
// DefaultClient is the default client. It is used by Send.

2
go.mod
View File

@ -1,3 +1,3 @@
module git.sr.ht/~adnano/gmi
module git.sr.ht/~adnano/go-gemini
go 1.15

View File

@ -1,4 +1,4 @@
package gmi
package gemini
import (
"bufio"

View File

@ -1,4 +1,4 @@
package gmi
package gemini
import (
"bufio"

View File

@ -1,4 +1,4 @@
package gmi
package gemini
import (
"bufio"
@ -45,10 +45,10 @@ type responderKey struct {
// Wildcard patterns are supported (e.g. *.example.com).
func (s *Server) Register(pattern string, responder Responder) {
if pattern == "" {
panic("gmi: invalid pattern")
panic("gemini: invalid pattern")
}
if responder == nil {
panic("gmi: nil responder")
panic("gemini: nil responder")
}
if s.responders == nil {
s.responders = map[responderKey]Responder{}
@ -121,7 +121,7 @@ func (s *Server) Serve(l net.Listener) error {
if max := 1 * time.Second; tempDelay > max {
tempDelay = max
}
log.Printf("gmi: Accept error: %v; retrying in %v", err, tempDelay)
log.Printf("gemini: Accept error: %v; retrying in %v", err, tempDelay)
time.Sleep(tempDelay)
continue
}
@ -275,7 +275,7 @@ func SensitiveInput(w *ResponseWriter, r *Request, prompt string) (string, bool)
if r.URL.ForceQuery || r.URL.RawQuery != "" {
return r.URL.RawQuery, true
}
w.WriteHeader(StatusInput, prompt)
w.WriteHeader(StatusSensitiveInput, prompt)
return "", false
}
@ -487,13 +487,13 @@ func (mux *ServeMux) Handle(pattern string, responder Responder) {
defer mux.mu.Unlock()
if pattern == "" {
panic("gmi: invalid pattern")
panic("gemini: invalid pattern")
}
if responder == nil {
panic("gmi: nil responder")
panic("gemini: nil responder")
}
if _, exist := mux.m[pattern]; exist {
panic("gmi: multiple registrations for " + pattern)
panic("gemini: multiple registrations for " + pattern)
}
if mux.m == nil {
@ -524,7 +524,7 @@ func appendSorted(es []muxEntry, e muxEntry) []muxEntry {
// HandleFunc registers the responder function for the given pattern.
func (mux *ServeMux) HandleFunc(pattern string, responder func(*ResponseWriter, *Request)) {
if responder == nil {
panic("gmi: nil responder")
panic("gemini: nil responder")
}
mux.Handle(pattern, ResponderFunc(responder))
}

View File

@ -1,4 +1,4 @@
package gmi
package gemini
import (
"bufio"

View File

@ -1,4 +1,4 @@
package gmi
package gemini
import (
"bufio"

View File

@ -6,7 +6,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gmi
package gemini
import (
"crypto/x509"