Exemplo n.º 1
0
// InitPProfRouter adds the routes for PProf.
func InitPProfRouter(parentRouter *web.Router) {
	// Setup the /pprof subrouter.
	pprofRouter := parentRouter.Subrouter(Context{}, "/debug/pprof")
	pprofRouter.Get("/", (*Context).Index)
	pprofRouter.Get("/heap", (*Context).Heap)
	pprofRouter.Get("/goroutine", (*Context).Goroutine)
	pprofRouter.Get("/threadcreate", (*Context).Threadcreate)
	pprofRouter.Get("/block", (*Context).Threadcreate)
	pprofRouter.Get("/profile", (*Context).Profile)
	pprofRouter.Get("/symbol", (*Context).Symbol)
}
Exemplo n.º 2
0
func InstallHandler(rootRouter *web.Router, rc *RunningContext) {

	runningContext = rc

	c := context{}

	v2 := rootRouter.Subrouter(c, "/v2").
		Middleware((*context).commonHeader)

	v2.Subrouter(c, "/token").
		Middleware((*context).parseRequest).
		Middleware((*context).authAccess).
		Get("/", (*context).writeToken)
}
Exemplo n.º 3
0
func addRoutes(baseRouter *web.Router, globalContext interface{}, routeConfs map[string]map[Method]interface{}) error {
	for routeName, routeConf := range routeConfs {
		var router *web.Router
		if routeConf[Middleware] != nil {
			router = baseRouter.Subrouter(globalContext, routeName)
			routeName = "/"
			addMiddleware(router, routeConf[Middleware])
		} else {
			router = baseRouter
		}
		v := reflect.ValueOf(router)
		for detourMethod, handler := range routeConf {
			if detourMethod == Middleware {
				continue
			}
			methodFn := v.MethodByName(string(detourMethod))
			_ = methodFn.Call([]reflect.Value{reflect.ValueOf(routeName), reflect.ValueOf(handler)})
		}
	}
	return nil
}
Exemplo n.º 4
0
func InstallHandler(rootRouter *web.Router, rc *RunningContext) {

	runningContext = rc

	c := context{}

	v1 := rootRouter.Subrouter(c, "/v1").
		Middleware((*context).commonHeader).
		Get("/", (*context).ping).
		Get("/_ping", (*context).ping)

	v1.Subrouter(c, "/users").
		Middleware((*context).authAccess).
		Get("/", handler.Empty).
		Post("/", handler.Empty).
		Put("/", handler.Empty)

	v1.Subrouter(c, "/repositories").
		Middleware((*context).readNamespace).
		Middleware((*context).authAccess).
		Middleware((*context).generateToken).
		// auth
		Put("/:repo/auth", handler.Empty).
		Put("/:namespace/:repo/auth", handler.Empty).
		// images
		Get("/:repo/images", (*context).getImages).
		Get("/:namespace/:repo/images", (*context).getImages).
		Put("/:repo/images", (*context).createImages).
		Put("/:namespace/:repo/images", (*context).createImages).
		// layer
		Get("/:repo/layer/:image/access", (*context).sayAccess).
		Get("/:namespace/:repo/layer/:image/access", (*context).sayAccess).
		// repo
		Put("/:repo", (*context).createRepo).
		Put("/:namespace/:repo/", (*context).createRepo).
		Delete("/:repo/", (*context).deleteRepo).
		Delete("/:namespace/:repo", (*context).deleteRepo)
}