From 0e9d87db72a7c2e69476bf0b847d9c74f9bbed5a Mon Sep 17 00:00:00 2001 From: cremesk Date: Wed, 31 Jul 2019 19:30:57 +0200 Subject: [PATCH] change to envs --- .drone.yml | 22 -------------------- .gitignore | 2 -- .travis.yml | 10 +++++++++ Makefile | 14 +++---------- README.md | 22 +++++--------------- _config.yml | 1 - cmd/gopherproxy/main.go | 4 ++-- go.mod | 6 ------ go.sum | 9 -------- gopherproxy.go | 34 +++++++++++++++++++++++++------ .goreleaser.yml => goreleaser.yml | 0 markdown.go | 17 ++++++++++++++++ template.go | 19 ++++++++++++++--- 13 files changed, 81 insertions(+), 79 deletions(-) delete mode 100644 .drone.yml create mode 100644 .travis.yml delete mode 100644 _config.yml delete mode 100644 go.mod delete mode 100644 go.sum rename .goreleaser.yml => goreleaser.yml (100%) create mode 100644 markdown.go diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 0065a03..0000000 --- a/.drone.yml +++ /dev/null @@ -1,22 +0,0 @@ -kind: pipeline -name: default - -steps: - - name: build - image: golang:latest - commands: - - make test - - - name: coverage - image: plugins/codecov - settings: - token: - from_secret: codecov-token - - - name: notify - image: plugins/webhook - urls: https://msgbus.mills.io/ci.mills.io - when: - status: - - success - - failure diff --git a/.gitignore b/.gitignore index 32c3689..4e35f8a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ *~ dist *.bak -coverage.txt - gopherproxy diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8763a71 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: go +sudo: false +go: + - tip +before_install: + - go get github.com/mattn/goveralls +script: + - $HOME/gopath/bin/goveralls -service=travis-ci +after_success: + - test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash diff --git a/Makefile b/Makefile index 12850e1..6fef3e6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: dev build profile bench test clean +.PHONY: dev build clean all: dev @@ -6,16 +6,8 @@ dev: build ./gopherproxy -bind 127.0.0.1:8000 build: clean + go get ./... go build -o ./gopherproxy ./cmd/gopherproxy/main.go -profile: - @go test -cpuprofile cpu.prof -memprofile mem.prof -v -bench . - -bench: - @go test -v -bench . - -test: - @go test -v -race -cover -coverprofile=coverage.txt -covermode=atomic . - clean: - @git clean -f -d -X + rm -rf gopherproxy diff --git a/README.md b/README.md index 7215e2b..cfd3bad 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ # Gopher (RFC 1436) Web Proxy - -[![Build Status](https://cloud.drone.io/api/badges/prologic/gopherproxy/status.svg)](https://cloud.drone.io/prologic/gopherproxy) -[![CodeCov](https://codecov.io/gh/prologic/gopherproxy/branch/master/graph/badge.svg)](https://codecov.io/gh/prologic/gopherproxy) -[![Go Report Card](https://goreportcard.com/badge/prologic/gopherproxy)](https://goreportcard.com/report/prologic/gopherproxy) -[![GoDoc](https://godoc.org/github.com/prologic/gopherproxy?status.svg)](https://godoc.org/github.com/prologic/gopherproxy) -[![Sourcegraph](https://sourcegraph.com/github.com/prologic/gopherproxy/-/badge.svg)](https://sourcegraph.com/github.com/prologic/gopherproxy?badge) +[![Build Status](https://travis-ci.org/prologic/gopherproxy.svg)](https://travis-ci.org/prologic/gopherproxy) +[![GoDoc](https://godoc.org/github.com/prologic/gopherproxy?status.svg)](https://godoc.org/github.com/prologic/gopherproxy) +[![Wiki](https://img.shields.io/badge/docs-wiki-blue.svg)](https://github.com/prologic/gopherproxy/wiki) +[![Go Report Card](https://goreportcard.com/badge/github.com/prologic/gopherproxy)](https://goreportcard.com/report/github.com/prologic/gopherproxy) +[![Coverage](https://coveralls.io/repos/prologic/gopherproxy/badge.svg)](https://coveralls.io/r/prologic/gopherproxy) gopherproxy is a Gopher (RFC 1436) Web Proxy that acts as a gateway into Gopherspace by proxying standard Web HTTP requests to Gopher requests of the target server. @@ -41,17 +40,6 @@ $ gopherproxy Then simply visit: http://localhost/gopher.floodgap.com -## Related - -Related projects: - -- [go-gopher](https://github.com/prologic/go-gopher) - go-gopher is the Gopher client and server library used by gopherproxy - -- [gopherclient](https://github.com/prologic/gopherclient) - gopherclient is a cross-platform QT/QML GUI Gopher Client - using the gopherproxy library as its backend. - ## License MIT diff --git a/_config.yml b/_config.yml deleted file mode 100644 index 3397c9a..0000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-architect \ No newline at end of file diff --git a/cmd/gopherproxy/main.go b/cmd/gopherproxy/main.go index 84bde30..d9602c0 100644 --- a/cmd/gopherproxy/main.go +++ b/cmd/gopherproxy/main.go @@ -4,7 +4,7 @@ import ( "flag" "log" - "github.com/prologic/gopherproxy" + "tildegit.org/tildeverse/gopherproxy" ) var ( @@ -12,7 +12,7 @@ var ( // (opt -> env -> config -> default) bind = flag.String("bind", "0.0.0.0:8000", "[int]:port to bind to") robotsfile = flag.String("robots-file", "robots.txt", "robots.txt file") - uri = flag.String("uri", "floodgap.com", ":[port] to proxy to") + uri = flag.String("uri", "tilde.team", ":[port] to proxy to") ) func main() { diff --git a/go.mod b/go.mod deleted file mode 100644 index fa60472..0000000 --- a/go.mod +++ /dev/null @@ -1,6 +0,0 @@ -module github.com/prologic/gopherproxy - -require ( - github.com/prologic/go-gopher v0.0.0-20181230133552-0c68ed5f58b0 - github.com/temoto/robotstxt v0.0.0-20180810133444-97ee4a9ee6ea -) diff --git a/go.sum b/go.sum deleted file mode 100644 index 3474014..0000000 --- a/go.sum +++ /dev/null @@ -1,9 +0,0 @@ -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prologic/go-gopher v0.0.0-20181230133552-0c68ed5f58b0 h1:10LO/S8HVjIuEHsHea//Cena1Ztgy23f/e8HFC0w5ow= -github.com/prologic/go-gopher v0.0.0-20181230133552-0c68ed5f58b0/go.mod h1:LiuwIXz4es4YIUOD6yRv8mES9n9dFbe4z0+TcrLkhXg= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/temoto/robotstxt v0.0.0-20180810133444-97ee4a9ee6ea h1:hH8P1IiDpzRU6ZDbDh/RDnVuezi2oOXJpApa06M0zyI= -github.com/temoto/robotstxt v0.0.0-20180810133444-97ee4a9ee6ea/go.mod h1:aOux3gHPCftJ3KHq6Pz/AlDjYJ7Y+yKfm1gU/3B0u04= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/gopherproxy.go b/gopherproxy.go index 42f67cf..686ca73 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -1,6 +1,7 @@ package gopherproxy import ( + "bytes" "fmt" "html/template" "io" @@ -10,9 +11,8 @@ import ( "net/url" "strings" + gopher "github.com/prologic/go-gopher" "github.com/temoto/robotstxt" - - "github.com/prologic/go-gopher" ) type Item struct { @@ -71,9 +71,10 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, hostport str } return tpl.Execute(w, struct { - Title string - Lines []Item - }{title, out}) + Title string + Lines []Item + Gophermap bool + }{title, out, true}) } // GopherHandler returns a Handler that proxies requests @@ -125,7 +126,28 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, uri } if res.Body != nil { - io.Copy(w, res.Body) + if strings.HasSuffix(uri, ".md") { + // handle markdown + tpl.Execute(w, struct { + Title string + MdText template.HTML + Gophermap bool + Pre bool + }{uri, renderMd(res.Body), false, false}) + + } else if strings.HasSuffix(uri, ".txt") { + // handle .txt files + buf := new(bytes.Buffer) + buf.ReadFrom(res.Body) + tpl.Execute(w, struct { + Title string + MdText string + Gophermap bool + Pre bool + }{uri, buf.String(), false, true}) + } else { + io.Copy(w, res.Body) + } } else { if err := renderDirectory(w, tpl, hostport, res.Dir); err != nil { io.WriteString(w, fmt.Sprintf("Error:
%s
", err)) diff --git a/.goreleaser.yml b/goreleaser.yml similarity index 100% rename from .goreleaser.yml rename to goreleaser.yml diff --git a/markdown.go b/markdown.go new file mode 100644 index 0000000..21399f3 --- /dev/null +++ b/markdown.go @@ -0,0 +1,17 @@ +package gopherproxy + +import ( + "bytes" + "html/template" + "io" + "strings" + + "github.com/gomarkdown/markdown" +) + +func renderMd(b io.Reader) template.HTML { + buf := new(bytes.Buffer) + buf.ReadFrom(b) + md := string(markdown.ToHTML(buf.Bytes(), nil, nil)) + return template.HTML(strings.Replace(md, " + {{.Title}} + +
-
+{{if .Gophermap}}
 {{range .Lines}} {{if .Link}}({{.Type}}) {{.Text}}{{else}}      {{.Text}}{{end}}
-{{end}}
+{{end}} +
+{{else}} +{{if .Pre}}
{{end}}
+{{.MdText}}
+{{if .Pre}}
{{end}} +{{end}}
+
+ + -` + +`