forked from hswaw/hscloud
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
|
// A minimal redirector for b/123 style links to redmine.
|
|||
|
|
|||
|
package main
|
|||
|
|
|||
|
import (
|
|||
|
"fmt"
|
|||
|
"regexp"
|
|||
|
|
|||
|
"github.com/golang/glog"
|
|||
|
|
|||
|
"flag"
|
|||
|
"net/http"
|
|||
|
)
|
|||
|
|
|||
|
func init() {
|
|||
|
flag.Set("logtostderr", "true")
|
|||
|
}
|
|||
|
|
|||
|
var (
|
|||
|
flagListen string
|
|||
|
flagTarget string
|
|||
|
flagProject string
|
|||
|
|
|||
|
reIssue = regexp.MustCompile(`^/([0-9]+)$`)
|
|||
|
)
|
|||
|
|
|||
|
func main() {
|
|||
|
flag.StringVar(&flagListen, "b_listen", "0.0.0.0:8000", "Address to listen at")
|
|||
|
flag.StringVar(&flagTarget, "b_target", "issues.hackerspace.pl", "Redmine instance address")
|
|||
|
flag.StringVar(&flagProject, "b_project", "hswaw", "Redmine project name")
|
|||
|
flag.Parse()
|
|||
|
|
|||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|||
|
scheme := r.URL.Scheme
|
|||
|
if scheme == "" {
|
|||
|
scheme = "https"
|
|||
|
}
|
|||
|
if r.URL.Path == "/" {
|
|||
|
http.Redirect(w, r, fmt.Sprintf("%s://%s/my/page", scheme, flagTarget), 302)
|
|||
|
return
|
|||
|
}
|
|||
|
if r.URL.Path == "/new" {
|
|||
|
http.Redirect(w, r, fmt.Sprintf("%s://%s/projects/%s/issues/new", scheme, flagTarget, flagProject), 302)
|
|||
|
return
|
|||
|
}
|
|||
|
if matches := reIssue.FindStringSubmatch(r.URL.Path); len(matches) == 2 {
|
|||
|
num := matches[1]
|
|||
|
http.Redirect(w, r, fmt.Sprintf("%s://%s/issues/%s", scheme, flagTarget, num), 302)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
fmt.Fprintf(w, `<!DOCTYPE html>
|
|||
|
<title>🅱️</title>
|
|||
|
<center><iframe width="1120" height="630" src="https://www.youtube.com/embed/el0PtDvg2AE?start=4994&autoplay=1" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></center>
|
|||
|
`)
|
|||
|
})
|
|||
|
|
|||
|
glog.Infof("Listening on %q...", flagListen)
|
|||
|
err := http.ListenAndServe(flagListen, nil)
|
|||
|
if err != nil {
|
|||
|
glog.Exit(err)
|
|||
|
}
|
|||
|
}
|