init
This commit is contained in:
parent
e733adb1d8
commit
1f97a8799d
@ -1,2 +1,3 @@
|
||||
# goget-redirect
|
||||
|
||||
Quick and dirty app to handle redirects for our infrastructure.
|
11
go.mod
Normal file
11
go.mod
Normal file
@ -0,0 +1,11 @@
|
||||
module git.kolaente.de/konrad/goget-redirect
|
||||
|
||||
require (
|
||||
github.com/labstack/echo v3.3.5+incompatible
|
||||
github.com/labstack/gommon v0.2.8 // indirect
|
||||
github.com/mattn/go-colorable v0.0.9 // indirect
|
||||
github.com/mattn/go-isatty v0.0.4 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 // indirect
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 // indirect
|
||||
)
|
14
go.sum
Normal file
14
go.sum
Normal file
@ -0,0 +1,14 @@
|
||||
github.com/labstack/echo v3.3.5+incompatible h1:9PfxPUmasKzeJor9uQTaXLT6WUG/r+vSTmvXxvv3JO4=
|
||||
github.com/labstack/echo v3.3.5+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
|
||||
github.com/labstack/gommon v0.2.8 h1:JvRqmeZcfrHC5u6uVleB4NxxNbzx6gpbJiQknDbKQu0=
|
||||
github.com/labstack/gommon v0.2.8/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
|
||||
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4 h1:gKMu1Bf6QINDnvyZuTaACm9ofY+PRh+5vFz4oxBZeF8=
|
||||
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4/go.mod h1:50wTf68f99/Zt14pr046Tgt3Lp2vLyFZKzbFXTOabXw=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
59
main.go
Normal file
59
main.go
Normal file
@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"html/template"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const BaseUrl = `https://git.kolaente.de/vikunja`
|
||||
const Domain = `code.vikunja.io`
|
||||
const GoGetTemplate = `<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="go-import" content="` + Domain + `{{.}} git ` + BaseUrl + `{{.}}.git">
|
||||
<meta name="go-source" content="` + Domain + `{{.}} _ ` + BaseUrl + `{{.}}/src/branch/master{/dir} ` + BaseUrl + `{{.}}/src/branch/master{/dir}/{file}#L{line}">
|
||||
<meta http-equiv="refresh" content="0; url=` + BaseUrl + `{{.}}" />
|
||||
</head>
|
||||
<body>
|
||||
go get ` + Domain + `{{.}}
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
type Template struct {
|
||||
templates *template.Template
|
||||
}
|
||||
|
||||
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
||||
return t.templates.ExecuteTemplate(w, name, data)
|
||||
}
|
||||
|
||||
func redirectToBase(c echo.Context) error {
|
||||
return c.Redirect(http.StatusFound, BaseUrl+c.Request().URL.String())
|
||||
}
|
||||
|
||||
func showGoGetMeta(c echo.Context) error {
|
||||
switch c.Param("repo") {
|
||||
case "web":
|
||||
return c.Render(http.StatusOK, "goget", c.Request().URL.Path)
|
||||
case "api":
|
||||
return c.Render(http.StatusOK, "goget", c.Request().URL.Path)
|
||||
default:
|
||||
return redirectToBase(c)
|
||||
}
|
||||
return redirectToBase(c)
|
||||
}
|
||||
|
||||
func main() {
|
||||
e := echo.New()
|
||||
renderer := &Template{
|
||||
templates: template.Must(template.New("goget").Parse(GoGetTemplate)),
|
||||
}
|
||||
e.Renderer = renderer
|
||||
|
||||
e.GET("/*", redirectToBase)
|
||||
e.GET("/:repo", showGoGetMeta)
|
||||
e.Logger.Fatal(e.Start(":8080"))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user