From f0345f349594b3bb93a45827c7f99688ce73ae34 Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Sat, 24 Oct 2020 15:15:32 -0400 Subject: [PATCH] Rename repository to go-gemini --- LICENSE | 2 +- README.md | 4 ++-- cert.go | 2 +- client.go | 2 +- doc.go | 24 ++++++++++++------------ examples/auth.go | 2 +- examples/cert.go | 2 +- examples/client.go | 2 +- examples/server.go | 2 +- fs.go | 2 +- gmi.go => gemini.go | 16 ++++++++-------- go.mod | 2 +- request.go | 2 +- response.go | 2 +- server.go | 18 +++++++++--------- text.go | 2 +- tofu.go | 2 +- vendor.go | 2 +- 18 files changed, 45 insertions(+), 45 deletions(-) rename gmi.go => gemini.go (82%) diff --git a/LICENSE b/LICENSE index f7f288a..71ab8af 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index bfbd80c..de38933 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/cert.go b/cert.go index 6443ed8..a19a2bf 100644 --- a/cert.go +++ b/cert.go @@ -1,4 +1,4 @@ -package gmi +package gemini import ( "crypto" diff --git a/client.go b/client.go index a513a0a..dac0329 100644 --- a/client.go +++ b/client.go @@ -1,4 +1,4 @@ -package gmi +package gemini import ( "bufio" diff --git a/doc.go b/doc.go index 84dea50..9d519a0 100644 --- a/doc.go +++ b/doc.go @@ -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 diff --git a/examples/auth.go b/examples/auth.go index 058458b..bb07658 100644 --- a/examples/auth.go +++ b/examples/auth.go @@ -7,7 +7,7 @@ import ( "fmt" "log" - "git.sr.ht/~adnano/gmi" + gmi "git.sr.ht/~adnano/go-gemini" ) type user struct { diff --git a/examples/cert.go b/examples/cert.go index 4c16a01..dc6cc40 100644 --- a/examples/cert.go +++ b/examples/cert.go @@ -11,7 +11,7 @@ import ( "os" "time" - "git.sr.ht/~adnano/gmi" + gmi "git.sr.ht/~adnano/go-gemini" ) func main() { diff --git a/examples/client.go b/examples/client.go index 8d818c3..eb25301 100644 --- a/examples/client.go +++ b/examples/client.go @@ -10,7 +10,7 @@ import ( "os" "time" - "git.sr.ht/~adnano/gmi" + gmi "git.sr.ht/~adnano/go-gemini" ) var ( diff --git a/examples/server.go b/examples/server.go index 8b05bce..9ef4b8d 100644 --- a/examples/server.go +++ b/examples/server.go @@ -11,7 +11,7 @@ import ( "os" "time" - "git.sr.ht/~adnano/gmi" + gmi "git.sr.ht/~adnano/go-gemini" ) func main() { diff --git a/fs.go b/fs.go index 6157fb0..9ea375c 100644 --- a/fs.go +++ b/fs.go @@ -1,4 +1,4 @@ -package gmi +package gemini import ( "io" diff --git a/gmi.go b/gemini.go similarity index 82% rename from gmi.go rename to gemini.go index c36e96e..f03fd82 100644 --- a/gmi.go +++ b/gemini.go @@ -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. diff --git a/go.mod b/go.mod index 91e9c9b..f850117 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module git.sr.ht/~adnano/gmi +module git.sr.ht/~adnano/go-gemini go 1.15 diff --git a/request.go b/request.go index 7b2d209..18ebd0d 100644 --- a/request.go +++ b/request.go @@ -1,4 +1,4 @@ -package gmi +package gemini import ( "bufio" diff --git a/response.go b/response.go index 975425a..81d8dea 100644 --- a/response.go +++ b/response.go @@ -1,4 +1,4 @@ -package gmi +package gemini import ( "bufio" diff --git a/server.go b/server.go index d33a234..e692db0 100644 --- a/server.go +++ b/server.go @@ -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)) } diff --git a/text.go b/text.go index 5e34ef5..e41424a 100644 --- a/text.go +++ b/text.go @@ -1,4 +1,4 @@ -package gmi +package gemini import ( "bufio" diff --git a/tofu.go b/tofu.go index eedffb5..f832e47 100644 --- a/tofu.go +++ b/tofu.go @@ -1,4 +1,4 @@ -package gmi +package gemini import ( "bufio" diff --git a/vendor.go b/vendor.go index 207159a..99e11b3 100644 --- a/vendor.go +++ b/vendor.go @@ -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"