Beispiel #1
0
// NewHandler adds routes and handlers to an existing parent router (or
// creates one if parent is nil). Middleware is injected between mux and the
// handler functions (so you have access to gorilla/context for example)
func NewHandler(svc vcsstore.Service, gitTrans git.GitTransporter, parent *mux.Router, mw ...Middleware) *Handler {
	router := vcsclient.NewRouter(parent)
	r := (*mux.Router)(router)

	h := &Handler{
		Service:        svc,
		GitTransporter: gitTrans,
		router:         router,
		Log:            log.New(ioutil.Discard, "", 0),
		middleware:     mw,
	}

	handler := func(handlerFunc robustHandlerFunc) robustHandler {
		return robustHandler{h, handlerFunc}
	}

	r.Get(git.RouteGitInfoRefs).Handler(handler(h.serveInfoRefs))
	r.Get(git.RouteGitUploadPack).Handler(handler(h.serveUploadPack))
	r.Get(git.RouteGitReceivePack).Handler(handler(h.serveReceivePack))

	r.Get(vcsclient.RouteRoot).Handler(handler(h.serveRoot))
	r.Get(vcsclient.RouteRepo).Handler(handler(h.serveRepo))
	r.Get(vcsclient.RouteRepoCreateOrUpdate).Handler(handler(h.serveRepoCreateOrUpdate))
	r.Get(vcsclient.RouteRepoBlameFile).Handler(handler(h.serveRepoBlameFile))
	r.Get(vcsclient.RouteRepoBranch).Handler(handler(h.serveRepoBranch))
	r.Get(vcsclient.RouteRepoBranches).Handler(handler(h.serveRepoBranches))
	r.Get(vcsclient.RouteRepoCommit).Handler(handler(h.serveRepoCommit))
	r.Get(vcsclient.RouteRepoCommits).Handler(handler(h.serveRepoCommits))
	r.Get(vcsclient.RouteRepoCommitters).Handler(handler(h.serveRepoCommitters))
	r.Get(vcsclient.RouteRepoDiff).Handler(handler(h.serveRepoDiff))
	r.Get(vcsclient.RouteRepoCrossRepoDiff).Handler(handler(h.serveRepoCrossRepoDiff))
	r.Get(vcsclient.RouteRepoMergeBase).Handler(handler(h.serveRepoMergeBase))
	r.Get(vcsclient.RouteRepoCrossRepoMergeBase).Handler(handler(h.serveRepoCrossRepoMergeBase))
	r.Get(vcsclient.RouteRepoSearch).Handler(handler(h.serveRepoSearch))
	r.Get(vcsclient.RouteRepoRevision).Handler(handler(h.serveRepoRevision))
	r.Get(vcsclient.RouteRepoTag).Handler(handler(h.serveRepoTag))
	r.Get(vcsclient.RouteRepoTags).Handler(handler(h.serveRepoTags))
	r.Get(vcsclient.RouteRepoTreeEntry).Handler(handler(h.serveRepoTreeEntry))

	return h
}
Beispiel #2
0
func getCmd(args []string) {
	fs := flag.NewFlagSet("get", flag.ExitOnError)
	urlStr := fs.String("url", "http://localhost:"+defaultPort, "base URL to a running vcsstore API server")
	method := fs.String("method", "GET", "HTTP request method")
	fs.Usage = func() {
		fmt.Fprintln(os.Stderr, `usage: vcsstore get [options] repo-id [extra-path]

Gets a URL path from the server (optionally routing the request using datad).

The options are:
`)
		fs.PrintDefaults()
		os.Exit(1)
	}
	fs.Parse(args)

	if n := fs.NArg(); n != 1 && n != 2 {
		fs.Usage()
	}
	repoPath := fs.Arg(0)
	var extraPath string
	if fs.NArg() == 2 {
		extraPath = fs.Arg(1)
	}

	baseURL, err := url.Parse(*urlStr)
	if err != nil {
		log.Fatal(err)
	}

	router := vcsclient.NewRouter(nil)
	url := router.URLToRepo(repoPath)
	url.Path = strings.TrimPrefix(url.Path, "/")
	url = baseURL.ResolveReference(url)
	url.Path = filepath.Join(url.Path, extraPath)

	normalGet(*method, nil, url)
}
Beispiel #3
0
func repoCmd(args []string) {
	fs := flag.NewFlagSet("repo", flag.ExitOnError)
	fs.Usage = func() {
		fmt.Fprintln(os.Stderr, `usage: vcsstore repo [options] repo-id

Displays the directory to which a repository would be cloned.

The options are:
`)
		fs.PrintDefaults()
		os.Exit(1)
	}
	fs.Parse(args)

	if fs.NArg() != 1 {
		fs.Usage()
	}

	repoPath := fs.Arg(0)

	fmt.Println("RepositoryPath:      ", filepath.Join(*storageDir, vcsstore.EncodeRepositoryPath(repoPath)))
	fmt.Println("URL:                 ", vcsclient.NewRouter(nil).URLToRepo(repoPath))
}