aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2020-10-28 15:13:31 -0400
committerAdnan Maolood <[email protected]>2020-10-28 15:14:24 -0400
commit34ae2a9066c9fe2f614b356cc90b86f0da2165ee (patch)
treebbd6ebfaa84f18487d345aaf05867ba8ac0eb400
parentRefactor server certificates (diff)
downloadgo-gemini-34ae2a9066c9fe2f614b356cc90b86f0da2165ee.tar.xz
go-gemini-34ae2a9066c9fe2f614b356cc90b86f0da2165ee.zip
Use strings.Builder in Fingerprint
-rw-r--r--examples/server.go1
-rw-r--r--fs.go9
-rw-r--r--tofu.go9
3 files changed, 9 insertions, 10 deletions
diff --git a/examples/server.go b/examples/server.go
index 6c29cdd..7dfd331 100644
--- a/examples/server.go
+++ b/examples/server.go
@@ -7,6 +7,7 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
+ "fmt"
"io"
"log"
"os"
diff --git a/fs.go b/fs.go
index 9ed75d1..cc852b6 100644
--- a/fs.go
+++ b/fs.go
@@ -5,7 +5,6 @@ import (
"mime"
"os"
"path"
- "path/filepath"
)
func init() {
@@ -25,14 +24,14 @@ type fsHandler struct {
}
func (fsh fsHandler) Respond(w *ResponseWriter, r *Request) {
- path := path.Clean(r.URL.Path)
- f, err := fsh.Open(path)
+ p := path.Clean(r.URL.Path)
+ f, err := fsh.Open(p)
if err != nil {
w.WriteStatus(StatusNotFound)
return
}
// Detect mimetype
- ext := filepath.Ext(path)
+ ext := path.Ext(p)
mimetype := mime.TypeByExtension(ext)
w.SetMimetype(mimetype)
// Copy file to response writer
@@ -71,7 +70,7 @@ func ServeFile(w *ResponseWriter, fs FS, name string) {
return
}
// Detect mimetype
- ext := filepath.Ext(name)
+ ext := path.Ext(name)
mimetype := mime.TypeByExtension(ext)
w.SetMimetype(mimetype)
// Copy file to response writer
diff --git a/tofu.go b/tofu.go
index f832e47..73aead0 100644
--- a/tofu.go
+++ b/tofu.go
@@ -2,7 +2,6 @@ package gemini
import (
"bufio"
- "bytes"
"crypto/sha512"
"crypto/x509"
"fmt"
@@ -162,14 +161,14 @@ func appendKnownHost(w io.Writer, hostname string, c certInfo) (int, error) {
// Fingerprint returns the SHA-512 fingerprint of the provided certificate.
func Fingerprint(cert *x509.Certificate) string {
sum512 := sha512.Sum512(cert.Raw)
- var buf bytes.Buffer
+ var b strings.Builder
for i, f := range sum512 {
if i > 0 {
- fmt.Fprintf(&buf, ":")
+ b.WriteByte(':')
}
- fmt.Fprintf(&buf, "%02X", f)
+ fmt.Fprintf(&b, "%02X", f)
}
- return buf.String()
+ return b.String()
}
// defaultKnownHostsPath returns the default known_hosts path.