aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdnan Maolood <me@adnano.co>2021-02-24 23:18:41 -0500
committerDrew DeVault <sir@cmpwn.com>2021-02-25 08:52:04 -0500
commitfa95eaf041342e76eddb335c4c1e1a3887049407 (patch)
tree3dea3c165f3072af525402a2ce99d5e78192b24f
parentImplement support for "lang" media type parameter (diff)
downloadkineto-fa95eaf041342e76eddb335c4c1e1a3887049407.tar.bz2
kineto-fa95eaf041342e76eddb335c4c1e1a3887049407.zip
Use fmt.Fprintf instead of Write and Sprintf
-rw-r--r--main.go15
1 files changed, 7 insertions, 8 deletions
diff --git a/main.go b/main.go
index 0e0e08a..a69d179 100644
--- a/main.go
+++ b/main.go
@@ -419,12 +419,12 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
to, err := url.Parse(resp.Meta)
if err != nil {
w.WriteHeader(http.StatusBadGateway)
- w.Write([]byte(fmt.Sprintf("Gateway error: bad redirect %v", err)))
+ fmt.Fprintf(w, "Gateway error: bad redirect: %v", err)
}
next := req.URL.ResolveReference(to)
if next.Scheme != "gemini" {
w.WriteHeader(http.StatusOK)
- w.Write([]byte(fmt.Sprintf("This page is redirecting you to %s", next.String())))
+ fmt.Fprintf(w, "This page is redirecting you to %s", next)
return
}
if external {
@@ -434,7 +434,7 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
next.Scheme = r.URL.Scheme
w.Header().Add("Location", next.String())
w.WriteHeader(http.StatusFound)
- w.Write([]byte("Redirecting to " + next.String()))
+ fmt.Fprintf(w, "Redirecting to %s", next)
return
case 40, 41, 42, 43, 44:
w.WriteHeader(http.StatusServiceUnavailable)
@@ -457,8 +457,7 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
m, params, err := mime.ParseMediaType(resp.Meta)
if err != nil {
w.WriteHeader(http.StatusBadGateway)
- w.Write([]byte(fmt.Sprintf("Gateway error: %d %s: %v",
- resp.Status, resp.Meta, err)))
+ fmt.Fprintf(w, "Gateway error: %d %s: %v", resp.Status, resp.Meta, err)
return
}
@@ -512,7 +511,7 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
func main() {
var (
bind string = ":8080"
- css string = defaultCSS
+ css string = defaultCSS
)
opts, optind, err := getopt.Getopts(os.Args, "b:c:s:")
@@ -525,13 +524,13 @@ func main() {
bind = opt.Value
case 's':
cssContent, err := ioutil.ReadFile(opt.Value)
- if (err == nil) {
+ if err == nil {
css = string(cssContent)
} else {
log.Fatalf("Error opening custom CSS from '%s': %v", opt.Value, err)
}
+ }
}
-}
args := os.Args[optind:]
if len(args) != 1 {