/* Runs a barebones vanity server over HTTP. Usage ./toyohime [-index] [-nohealthz] fqdn [repo file] The "-index" flag enables an index page at "/" that lists all repos hosted on this server. The "-nohealthz" flag disables the "/healthz" endpoint that returns a 200 OK when everything is OK. The "-watch" flag watches the repo file for changes. When it is updated, the updated version will be used for serving. If repo file is not given, "./repos" is used. The file has the following format: pkgroot vcsScheme://vcsHost/user/repo pkgroot2 vcsScheme://vcsHost/user/repo2 vcsHost is either a Gogs server (that's what I use) or github.com. I'm open to supporting other VCSs but I'm not sure what that would look like. */ package main // go.jonnrb.io/vanity import ( "bufio" "bytes" "flag" "fmt" "html/template" "io" "log" "net/http" "net/url" "os" "strings" "time" "marisa.chaotic.ninja/toyohime" ) var ( showIndex = flag.Bool("index", false, "Show a list of repos at /") noHealthz = flag.Bool("nohealthz", false, "Disable healthcheck endpoint at /healthz") watch = flag.Bool("watch", false, "Watch repos file for changes and reload") listenPort = flag.String("listen", ":8080", "Port to bind on") ) var ( host string // param 1 reposPath string = "repos" // param 2 ) func serveRepo(mux *http.ServeMux, root string, u *url.URL) { vcsScheme, vcsHost := u.Scheme, u.Host // Get ["", "user", "repo"]. pathParts := strings.Split(u.Path, "/") if len(pathParts) != 3 { log.Fatalf("Repo URL must be of the form vcsScheme://vcsHost/user/repo but got %q", u.String()) } user, repo := pathParts[1], pathParts[2] importPath := host + "/" + root var h http.Handler if vcsHost == "github.com" { h = toyohime.GitHubHandler(importPath, user, repo, vcsScheme) } else { h = toyohime.GogsHandler(importPath, vcsHost, user, repo, vcsScheme) } mux.Handle("/"+root, h) mux.Handle("/"+root+"/", h) } func addRepoHandlers(mux *http.ServeMux, r io.Reader) error { indexMap := map[string]string{} sc := bufio.NewScanner(r) for sc.Scan() { fields := strings.Fields(sc.Text()) switch len(fields) { case 0: continue case 2: // Pass default: return fmt.Errorf("expected line of form \"path vcsScheme://vcsHost/user/repo\" but got %q", sc.Text()) } if *showIndex { indexMap[fields[0]] = fields[1] } path := fields[0] u, err := url.Parse(fields[1]) if err != nil { return fmt.Errorf("repo was not a valid URL: %q", fields[1]) } serveRepo(mux, path, u) } if !*showIndex { return nil } var b bytes.Buffer err := template.Must(template.New("").Parse(`
でホストされているインポート パス {{ html $host }}
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
|
{{ html $root }}PackageRepository {{ else }} Nothing here. {{ end }} |
~から明らかに盗まれた azukifont.com