Use fmt.Fprintf instead of Write and Sprintf
This commit is contained in:
parent
c2f510eb79
commit
fa95eaf041
1 changed files with 7 additions and 8 deletions
15
main.go
15
main.go
|
@ -419,12 +419,12 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
|
||||||
to, err := url.Parse(resp.Meta)
|
to, err := url.Parse(resp.Meta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadGateway)
|
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)
|
next := req.URL.ResolveReference(to)
|
||||||
if next.Scheme != "gemini" {
|
if next.Scheme != "gemini" {
|
||||||
w.WriteHeader(http.StatusOK)
|
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
|
return
|
||||||
}
|
}
|
||||||
if external {
|
if external {
|
||||||
|
@ -434,7 +434,7 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
|
||||||
next.Scheme = r.URL.Scheme
|
next.Scheme = r.URL.Scheme
|
||||||
w.Header().Add("Location", next.String())
|
w.Header().Add("Location", next.String())
|
||||||
w.WriteHeader(http.StatusFound)
|
w.WriteHeader(http.StatusFound)
|
||||||
w.Write([]byte("Redirecting to " + next.String()))
|
fmt.Fprintf(w, "Redirecting to %s", next)
|
||||||
return
|
return
|
||||||
case 40, 41, 42, 43, 44:
|
case 40, 41, 42, 43, 44:
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
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)
|
m, params, err := mime.ParseMediaType(resp.Meta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadGateway)
|
w.WriteHeader(http.StatusBadGateway)
|
||||||
w.Write([]byte(fmt.Sprintf("Gateway error: %d %s: %v",
|
fmt.Fprintf(w, "Gateway error: %d %s: %v", resp.Status, resp.Meta, err)
|
||||||
resp.Status, resp.Meta, err)))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +511,7 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
bind string = ":8080"
|
bind string = ":8080"
|
||||||
css string = defaultCSS
|
css string = defaultCSS
|
||||||
)
|
)
|
||||||
|
|
||||||
opts, optind, err := getopt.Getopts(os.Args, "b:c:s:")
|
opts, optind, err := getopt.Getopts(os.Args, "b:c:s:")
|
||||||
|
@ -525,13 +524,13 @@ func main() {
|
||||||
bind = opt.Value
|
bind = opt.Value
|
||||||
case 's':
|
case 's':
|
||||||
cssContent, err := ioutil.ReadFile(opt.Value)
|
cssContent, err := ioutil.ReadFile(opt.Value)
|
||||||
if (err == nil) {
|
if err == nil {
|
||||||
css = string(cssContent)
|
css = string(cssContent)
|
||||||
} else {
|
} else {
|
||||||
log.Fatalf("Error opening custom CSS from '%s': %v", opt.Value, err)
|
log.Fatalf("Error opening custom CSS from '%s': %v", opt.Value, err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
args := os.Args[optind:]
|
args := os.Args[optind:]
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
|
|
Loading…
Reference in a new issue