From f72073e6ef7e208b291cb98cf147f0feab115e8a Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Thu, 11 Jul 2019 22:59:40 +1000 Subject: [PATCH] Convert tabs to spaces when displaying --- cmd/pb/main.go | 11 +++++++++-- server.go | 11 +++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cmd/pb/main.go b/cmd/pb/main.go index 21a05f8..3aeb4f8 100644 --- a/cmd/pb/main.go +++ b/cmd/pb/main.go @@ -1,6 +1,7 @@ package main import ( + "log" "os" "github.com/prologic/pastebin/client" @@ -12,7 +13,7 @@ import ( const ( defaultConfig = "pastebin.conf" defaultUserConfig = "~/.pastebin.conf" - defaultURL = "https://localhost:8000" + defaultURL = "http://localhost:8000" ) func getDefaultConfig() string { @@ -36,5 +37,11 @@ func main() { flag.Parse() - client.NewClient(url, insecure).Paste(os.Stdin) + cli := client.NewClient(url, insecure) + + err := cli.Paste(os.Stdin) + if err != nil { + log.Printf("error posting paste: %s", err) + os.Exit(1) + } } diff --git a/server.go b/server.go index fe22801..173ce27 100644 --- a/server.go +++ b/server.go @@ -186,12 +186,15 @@ func (s *Server) ViewHandler() httprouter.Handle { return } - blob, ok := s.store.Get(uuid) + rawBlob, ok := s.store.Get(uuid) if !ok { http.Error(w, "Not Found", http.StatusNotFound) return } + blob := rawBlob.(string) + blob = strings.ReplaceAll(blob, "\t", " ") + switch accepts { case "text/html": s.render( @@ -200,14 +203,14 @@ func (s *Server) ViewHandler() httprouter.Handle { Blob string UUID string }{ - Blob: blob.(string), + Blob: blob, UUID: uuid, }, ) case "text/plain": - w.Write([]byte(blob.(string))) + w.Write([]byte(blob)) default: - w.Write([]byte(blob.(string))) + w.Write([]byte(blob)) } } }