Ejemplo n.º 1
0
// registerRoutes registers HTTP route handlers
func (d *daemon) registerRoutes(router *mux.Router) {
	// Add REST routes
	s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()

	s.HandleFunc("/plugin/allocAddress", makeHTTPHandler(master.AllocAddressHandler))
	s.HandleFunc("/plugin/releaseAddress", makeHTTPHandler(master.ReleaseAddressHandler))
	s.HandleFunc("/plugin/createEndpoint", makeHTTPHandler(master.CreateEndpointHandler))
	s.HandleFunc("/plugin/deleteEndpoint", makeHTTPHandler(master.DeleteEndpointHandler))
	s.HandleFunc("/plugin/svcProviderUpdate", makeHTTPHandler(master.ServiceProviderUpdateHandler))

	s = router.Methods("Get").Subrouter()
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetEndpointRESTEndpoint, "{id}"),
		get(false, d.endpoints))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetEndpointsRESTEndpoint),
		get(true, d.endpoints))
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetNetworkRESTEndpoint, "{id}"),
		get(false, d.networks))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetNetworksRESTEndpoint),
		get(true, d.networks))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetVersionRESTEndpoint), getVersion)
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetServiceRESTEndpoint, "{id}"),
		get(false, d.services))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetServicesRESTEndpoint),
		get(true, d.services))

}
Ejemplo n.º 2
0
// AddRoutes adds routes to a router instance. If there are middlewares defined
// for a route, a new negroni app is created and wrapped as a http.Handler
func AddRoutes(routes []Route, router *mux.Router) {
	var (
		handler http.Handler
		n       *negroni.Negroni
	)

	for _, route := range routes {
		// Add any specified middlewares
		if len(route.Middlewares) > 0 {
			n = negroni.New()

			for _, middleware := range route.Middlewares {
				n.Use(middleware)
			}

			// Wrap the handler in the negroni app with middlewares
			n.Use(negroni.Wrap(route.HandlerFunc))
			handler = n
		} else {
			handler = route.HandlerFunc
		}

		router.Methods(route.Method).
			Path(route.Pattern).
			Name(route.Name).
			Handler(handler)
	}
}
Ejemplo n.º 3
0
// RegisterControlRoutes registers the various control routes with a http mux.
func RegisterControlRoutes(router *mux.Router) {
	controlRouter := &controlRouter{
		probes: map[string]controlHandler{},
	}
	router.Methods("GET").Path("/api/control/ws").HandlerFunc(controlRouter.handleProbeWS)
	router.Methods("POST").MatcherFunc(URLMatcher("/api/control/{probeID}/{nodeID}/{control}")).HandlerFunc(controlRouter.handleControl)
}
Ejemplo n.º 4
0
// registerRoutes registers HTTP route handlers
func (d *daemon) registerRoutes(router *mux.Router) {
	// register web ui handlers
	d.registerWebuiHandler(router)

	// Add REST routes
	s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()

	s.HandleFunc("/plugin/allocAddress", makeHTTPHandler(master.AllocAddressHandler))
	s.HandleFunc("/plugin/releaseAddress", makeHTTPHandler(master.ReleaseAddressHandler))
	s.HandleFunc("/plugin/createEndpoint", makeHTTPHandler(master.CreateEndpointHandler))
	s.HandleFunc("/plugin/deleteEndpoint", makeHTTPHandler(master.DeleteEndpointHandler))

	s = router.Methods("Get").Subrouter()
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetEndpointRESTEndpoint, "{id}"),
		get(false, d.endpoints))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetEndpointsRESTEndpoint),
		get(true, d.endpoints))
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetNetworkRESTEndpoint, "{id}"),
		get(false, d.networks))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetNetworksRESTEndpoint),
		get(true, d.networks))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetVersionRESTEndpoint), getVersion)

	// See if we need to create the default tenant
	go objApi.CreateDefaultTenant()
}
Ejemplo n.º 5
0
//Register - registers an API Call with the router
func (call *APICall) Register(router *mux.Router) {
	log.Println("Call: ", call)
	router.Methods(call.Methods...).
		Name(call.Name).
		Path(call.Path).
		HandlerFunc(call.HandlerFunc)
}
Ejemplo n.º 6
0
// RegisterRoutes operates over `Routes` and registers all of them
func RegisterRoutes(router *mux.Router) *mux.Router {
	for _, route := range routes {
		router.Methods(route.Method).Path(route.Pattern).Name(route.Name).Handler(route.HandlerFunc)
	}
	router.PathPrefix("/").Handler(http.FileServer(assetFS()))
	return router
}
Ejemplo n.º 7
0
// RegisterReportPostHandler registers the handler for report submission
func RegisterReportPostHandler(a Adder, router *mux.Router) {
	post := router.Methods("POST").Subrouter()
	post.HandleFunc("/api/report", func(w http.ResponseWriter, r *http.Request) {
		var (
			rpt    report.Report
			reader = r.Body
			err    error
		)
		if strings.Contains(r.Header.Get("Content-Encoding"), "gzip") {
			reader, err = gzip.NewReader(r.Body)
			if err != nil {
				http.Error(w, err.Error(), http.StatusBadRequest)
				return
			}
		}

		decoder := gob.NewDecoder(reader).Decode
		if strings.HasPrefix(r.Header.Get("Content-Type"), "application/json") {
			decoder = json.NewDecoder(reader).Decode
		}
		if err := decoder(&rpt); err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		a.Add(rpt)
		if len(rpt.Pod.Nodes) > 0 {
			topologyRegistry.enableKubernetesTopologies()
		}
		w.WriteHeader(http.StatusOK)
	})
}
Ejemplo n.º 8
0
func setupHandlers(router *mux.Router) {
	GET := router.Methods("GET", "HEAD").Subrouter()
	POST := router.Methods("POST").Subrouter()

	GET.HandleFunc("/", httpIndex)
	GET.HandleFunc("/m/{id}", httpMeetup)

	POST.HandleFunc("/new", apiNew)
}
Ejemplo n.º 9
0
func (a *App) SetRoutes(router *mux.Router) error {
	// Load App specific routes
	a.LoadRoutes()

	// Create a router for defining the routes which require authenticationAuth_fix
	//For routes require auth, will be checked by a middleware which
	//return error immediately

	authReqdRouter := mux.NewRouter().StrictSlash(true)

	//create a negroni with LoginReqd middleware
	n := negroni.New(negroni.HandlerFunc(a.LoginRequired), negroni.Wrap(authReqdRouter))

	// Set routes for core which doesnot require authentication
	for _, route := range CORE_ROUTES_NOAUTH {
		if validApiVersion(route.Version) {
			urlPattern := fmt.Sprintf("%s/v%d/%s", DEFAULT_API_PREFIX, route.Version, route.Pattern)
			router.Methods(route.Method).Path(urlPattern).Name(route.Name).Handler(http.HandlerFunc(route.HandlerFunc))
		} else {
			logger.Get().Info("Skipped the route: %s as version: %d is un spported", route.Name, route.Version)
		}
	}

	// Set routes for core which require authentication
	for _, route := range CORE_ROUTES {
		if validApiVersion(route.Version) {
			urlPattern := fmt.Sprintf("%s/v%d/%s", DEFAULT_API_PREFIX, route.Version, route.Pattern)
			authReqdRouter.Methods(route.Method).Path(urlPattern).Name(route.Name).Handler(http.HandlerFunc(route.HandlerFunc))
			router.Handle(urlPattern, n)
		} else {
			logger.Get().Info("Skipped the route: %s as version: %d is un spported", route.Name, route.Version)
		}
	}

	//Set the provider specific routes here
	//All the provider specific routes are assumed to be authenticated
	for _, route := range a.routes {
		logger.Get().Debug("%s", route)
		if validApiVersion(route.Version) {
			urlPattern := fmt.Sprintf("%s/v%d/%s", DEFAULT_API_PREFIX, route.Version, route.Pattern)
			authReqdRouter.
				Methods(route.Method).
				Path(urlPattern).
				Name(route.Name).
				Handler(http.HandlerFunc(a.ProviderHandler))
			router.Handle(urlPattern, n)
		} else {
			logger.Get().Info("Skipped the route: %s as version: %d is un spported", route.Name, route.Version)
		}
	}

	return nil
}
Ejemplo n.º 10
0
// registerRoutes registers HTTP route handlers
func (d *MasterDaemon) registerRoutes(router *mux.Router) {
	// Add REST routes
	s := router.Headers("Content-Type", "application/json").Methods("Post").Subrouter()

	s.HandleFunc("/plugin/allocAddress", makeHTTPHandler(master.AllocAddressHandler))
	s.HandleFunc("/plugin/releaseAddress", makeHTTPHandler(master.ReleaseAddressHandler))
	s.HandleFunc("/plugin/createEndpoint", makeHTTPHandler(master.CreateEndpointHandler))
	s.HandleFunc("/plugin/deleteEndpoint", makeHTTPHandler(master.DeleteEndpointHandler))
	s.HandleFunc("/plugin/updateEndpoint", makeHTTPHandler(master.UpdateEndpointHandler))

	s = router.Methods("Get").Subrouter()

	// return netmaster version
	s.HandleFunc(fmt.Sprintf("/%s", master.GetVersionRESTEndpoint), getVersion)
	// Print info about the cluster
	s.HandleFunc(fmt.Sprintf("/%s", master.GetInfoRESTEndpoint), func(w http.ResponseWriter, r *http.Request) {
		info, err := d.getMasterInfo()
		if err != nil {
			log.Errorf("Error getting master state. Err: %v", err)
			http.Error(w, "Error getting master state", http.StatusInternalServerError)
			return
		}

		// convert to json
		resp, err := json.Marshal(info)
		if err != nil {
			http.Error(w,
				core.Errorf("marshalling json failed. Error: %s", err).Error(),
				http.StatusInternalServerError)
			return
		}
		w.Write(resp)
	})

	// services REST endpoints
	// FIXME: we need to remove once service inspect is added
	s.HandleFunc(fmt.Sprintf("/%s/%s", master.GetServiceRESTEndpoint, "{id}"),
		get(false, d.services))
	s.HandleFunc(fmt.Sprintf("/%s", master.GetServicesRESTEndpoint),
		get(true, d.services))

	// Debug REST endpoint for inspecting ofnet state
	s.HandleFunc("/debug/ofnet", func(w http.ResponseWriter, r *http.Request) {
		ofnetMasterState, err := d.ofnetMaster.InspectState()
		if err != nil {
			log.Errorf("Error fetching ofnet state. Err: %v", err)
			http.Error(w, "Error fetching ofnet state", http.StatusInternalServerError)
			return
		}
		w.Write(ofnetMasterState)
	})

}
// install handlers into the provided router
func (self *CentralBooking) InstallHandlers(router *mux.Router) {
	router.
		Methods("POST").
		Path("/register/instance").
		HandlerFunc(self.RegisterInstance)

	// apeing vault
	router.
		Methods("GET").
		Path("/sys/health").
		HandlerFunc(self.CheckHealth)
}
Ejemplo n.º 12
0
func (mgr *pxeManagerT) defineEtcdDiscoveryRoutes(etcdRouter *mux.Router) {
	etcdRouter.PathPrefix("/new").Methods("PUT").HandlerFunc(mgr.etcdDiscoveryNewCluster)

	tokenRouter := etcdRouter.PathPrefix("/{token:[a-f0-9]{32}}").Subrouter()
	tokenRouter.PathPrefix("/_config/size").Methods("GET").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
	tokenRouter.PathPrefix("/_config/size").Methods("PUT").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
	tokenRouter.PathPrefix("/{machine}").Methods("PUT").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
	tokenRouter.PathPrefix("/{machine}").Methods("GET").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
	tokenRouter.PathPrefix("/{machine}").Methods("DELETE").HandlerFunc(mgr.etcdDiscoveryProxyHandler)
	tokenRouter.Methods("GET").HandlerFunc(mgr.etcdDiscoveryProxyHandler)

	etcdRouter.Methods("GET").HandlerFunc(mgr.etcdDiscoveryHandler)
}
Ejemplo n.º 13
0
func Routes(r *mux.Router) {
	ps := r.Path("/paintings").Subrouter()
	ps.Methods("GET").Handler(listPaintings)
	ps.Methods("POST").Handler(createPainting)

	r.Methods("GET").Path("/paintings/categories").Handler(listCategories)
	r.Methods("GET").Path("/paintings/media").Handler(listMedia)

	p := r.Path("/paintings/{ID:[0-9]+}").Subrouter()
	p.Methods("GET").Handler(showPainting)
	p.Methods("PUT").Handler(editPainting)

	r.Methods("POST").Path("/paintings/{ID:[0-9]+}/rotate").Handler(rotatePainting)
}
Ejemplo n.º 14
0
func IntegrateRoutes(router *mux.Router) {

	router.
		Methods("POST").
		Path(ipnUrl).
		Name("ipn notification").
		HandlerFunc(processIPN)

	router.
		Methods("POST").
		Path(ipnRespondTaskUrl).
		Name("ipn notification responder task").
		HandlerFunc(ipnDoResponseTaskHandler)

}
Ejemplo n.º 15
0
// Register maps all routes to the appropriate handler
func Register(router *mux.Router, t *template.Template) {
	home := controllers.NewHome(t)
	router.HandleFunc("/", home.Index)
	router.HandleFunc("/about", home.About)
	router.NotFoundHandler = http.HandlerFunc(home.NotFound)

	account := controllers.NewAccount(t)
	router.HandleFunc("/login", account.Login)
	router.Methods("POST").Path("/signin").HandlerFunc(account.Signin)

	admin := controllers.NewAdmin(t)
	router.Handle("/admin", AuthHandler(admin.Index))

	static := http.StripPrefix("/static/", http.FileServer(http.Dir("./static/")))
	router.PathPrefix("/static/").Handler(static)
}
Ejemplo n.º 16
0
func (router *Router) AddHandler(args RouterArguments) {
	var r *mux.Router

	if sub, ok := router.sub[args.PathPrefix]; ok {
		r = sub
	} else {
		r = router.r
	}

	var prefix, path string
	if args.PathPrefix != "" {
		prefix = fmt.Sprintf("/%s", strings.Trim(args.PathPrefix, "/"))
	}
	path = fmt.Sprintf("/%s", strings.Trim(args.Path, "/"))
	r.Methods(args.Methods...).Path(fmt.Sprintf("%s%s", prefix, path)).HandlerFunc(args.Handler)
}
Ejemplo n.º 17
0
func IntegrateRoutes(router *mux.Router) {
	path := "/rest/auth"

	router.
		Methods("POST").
		Path(path + "/login").
		Name("loginUser").
		HandlerFunc(doLogin)

	router.
		Methods("POST").
		Path(path + "/logout").
		Name("logoutUser").
		HandlerFunc(doLogout)

}
Ejemplo n.º 18
0
func (endpoints Endpoints) Activate(router *mux.Router) {
	for _, endpoint := range endpoints {
		router.
			Methods(endpoint.Verb).
			Path(endpoint.Path).
			Handler(Handler(endpoint))
	}
}
Ejemplo n.º 19
0
// RegisterReportPostHandler registers the handler for report submission
func RegisterReportPostHandler(a Adder, router *mux.Router) {
	post := router.Methods("POST").Subrouter()
	post.HandleFunc("/api/report", requestContextDecorator(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		var (
			rpt                              report.Report
			reader                           = r.Body
			err                              error
			compressedSize, uncompressedSize uint64
		)

		if log.GetLevel() == log.DebugLevel {
			reader = byteCounter{next: reader, count: &compressedSize}
		}
		if strings.Contains(r.Header.Get("Content-Encoding"), "gzip") {
			reader, err = gzip.NewReader(reader)
			if err != nil {
				http.Error(w, err.Error(), http.StatusBadRequest)
				return
			}
		}

		if log.GetLevel() == log.DebugLevel {
			reader = byteCounter{next: reader, count: &uncompressedSize}
		}
		decoder := gob.NewDecoder(reader).Decode
		if strings.HasPrefix(r.Header.Get("Content-Type"), "application/json") {
			decoder = codec.NewDecoder(reader, &codec.JsonHandle{}).Decode
		} else if strings.HasPrefix(r.Header.Get("Content-Type"), "application/msgpack") {
			decoder = codec.NewDecoder(reader, &codec.MsgpackHandle{}).Decode
		}

		if err := decoder(&rpt); err != nil {
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		log.Debugf(
			"Received report sizes: compressed %d bytes, uncompressed %d bytes (%.2f%%)",
			compressedSize,
			uncompressedSize,
			float32(compressedSize)/float32(uncompressedSize)*100,
		)

		a.Add(ctx, rpt)
		w.WriteHeader(http.StatusOK)
	}))
}
Ejemplo n.º 20
0
// RegisterTopologyRoutes registers the various topology routes with a http mux.
func RegisterTopologyRoutes(router *mux.Router, r Reporter) {
	get := router.Methods("GET").Subrouter()
	get.HandleFunc("/api",
		gzipHandler(requestContextDecorator(apiHandler(r))))
	get.HandleFunc("/api/topology",
		gzipHandler(requestContextDecorator(topologyRegistry.makeTopologyList(r))))
	get.HandleFunc("/api/topology/{topology}",
		gzipHandler(requestContextDecorator(topologyRegistry.captureRenderer(r, handleTopology))))
	get.HandleFunc("/api/topology/{topology}/ws",
		requestContextDecorator(captureReporter(r, handleWebsocket))) // NB not gzip!
	get.MatcherFunc(URLMatcher("/api/topology/{topology}/{id}")).HandlerFunc(
		gzipHandler(requestContextDecorator(topologyRegistry.captureRenderer(r, handleNode))))
	get.HandleFunc("/api/report",
		gzipHandler(requestContextDecorator(makeRawReportHandler(r))))
	get.HandleFunc("/api/probes",
		gzipHandler(requestContextDecorator(makeProbeHandler(r))))
}
Ejemplo n.º 21
0
func registerSubroutes(router *mux.Router, routes application.Routes) {
	for _, route := range routes {
		router.
			Methods(route.Method).
			Path(route.Pattern).
			Name(route.Name).
			Handler(route.Handler)
	}
}
Ejemplo n.º 22
0
func SetupRouter(router *mux.Router, name string, routes Routes) {
	for _, route := range routes {
		router.
			Methods(route.Method).
			Path(route.Pattern).
			Name(name + route.Name).
			Handler(route.HandlerFunc)
	}
}
Ejemplo n.º 23
0
// PrepAppRoutes is used in apps to prepare app's routes
func PrepAppRoutes(s *mux.Router, confHandler *ConfHandler, routes []AppRoutes) *mux.Router {
	for _, route := range routes {
		// prepare handle wrappers
		var handler http.HandlerFunc

		handler = confHandler.Respond(route.SubrouterHandler)
		handler = WrapValidate(handler, confHandler.Config, route.Name)
		if route.Verb != "OPTIONS" {
			handler = WrapAuthorize(handler, confHandler.Config, route.Name)
			handler = WrapAuthenticate(handler, confHandler.Config, route.Name)
		}
		s.Methods(route.Verb).
			Path(route.Path).
			Handler(context.ClearHandler(handler))
	}

	return s

}
Ejemplo n.º 24
0
func IntegrateRoutes(router *mux.Router) {
	path := "/rest/export"

	router.
		Methods("GET").
		Path(path + "/xlsx").
		Name("export").
		HandlerFunc(UserService.AsAdmin(exportXlsxHandler))

}
Ejemplo n.º 25
0
Archivo: http.go Proyecto: n054/weave
func (router *NetworkRouter) HandleHTTP(muxRouter *mux.Router) {

	muxRouter.Methods("POST").Path("/connect").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if err := r.ParseForm(); err != nil {
			http.Error(w, fmt.Sprint("unable to parse form: ", err), http.StatusBadRequest)
		}
		if errors := router.InitiateConnections(r.Form["peer"], r.FormValue("replace") == "true"); len(errors) > 0 {
			http.Error(w, common.ErrorMessages(errors), http.StatusBadRequest)
		}
	})

	muxRouter.Methods("POST").Path("/forget").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if err := r.ParseForm(); err != nil {
			http.Error(w, fmt.Sprint("unable to parse form: ", err), http.StatusBadRequest)
		}
		router.ForgetConnections(r.Form["peer"])
	})

}
Ejemplo n.º 26
0
// AddRoutes adds routes to a router instance. If there are middlewares defined
// for a route, a new negroni app is created and wrapped as a http.Handler
func AddRoutes(routes []Route, router *mux.Router) {
	for _, route := range routes {
		var handler http.Handler
		if len(route.Middlewares) > 0 {
			n := negroni.New()
			for _, middleware := range route.Middlewares {
				n.Use(middleware)
			}
			n.Use(negroni.Wrap(route.HandlerFunc))
			handler = n
		} else {
			handler = route.HandlerFunc
		}

		router.Methods(route.Methods...).
			Path(route.Pattern).
			Name(route.Name).
			Handler(handler)
	}
}
Ejemplo n.º 27
0
// TopologyHandler registers the various topology routes with a http mux.
//
// The returned http.Handler has to be passed directly to http.ListenAndServe,
// and cannot be nested inside another gorrilla.mux.
//
// Routes which should be matched before the topology routes should be added
// to a router and passed in preRoutes.  Routes to be matches after topology
// routes should be added to a router and passed to postRoutes.
func TopologyHandler(c Reporter, preRoutes *mux.Router, postRoutes http.Handler) http.Handler {
	get := preRoutes.Methods("GET").Subrouter()
	get.HandleFunc("/api", gzipHandler(apiHandler))
	get.HandleFunc("/api/topology", gzipHandler(topologyRegistry.makeTopologyList(c)))
	get.HandleFunc("/api/topology/{topology}",
		gzipHandler(topologyRegistry.captureRenderer(c, handleTopology)))
	get.HandleFunc("/api/topology/{topology}/ws",
		topologyRegistry.captureRenderer(c, handleWs)) // NB not gzip!
	get.HandleFunc("/api/report", gzipHandler(makeRawReportHandler(c)))

	// We pull in the http.DefaultServeMux to get the pprof routes
	preRoutes.PathPrefix("/debug/pprof").Handler(http.DefaultServeMux)

	if postRoutes != nil {
		preRoutes.PathPrefix("/").Handler(postRoutes)
	}

	// We have to handle the node details path manually due to
	// various bugs in gorilla.mux and Go URL parsing.  See #804.
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		vars, match := matchURL(r, "/api/topology/{topology}/{id}")
		if !match {
			preRoutes.ServeHTTP(w, r)
			return
		}

		topologyID := vars["topology"]
		nodeID := vars["id"]
		if nodeID == "ws" {
			preRoutes.ServeHTTP(w, r)
			return
		}

		handler := gzipHandler(topologyRegistry.captureRendererWithoutFilters(
			c, topologyID, handleNode(nodeID),
		))
		handler.ServeHTTP(w, r)
	})
}
Ejemplo n.º 28
0
func IntegrateRoutes(router *mux.Router) {
	path := "/rest/user"

	router.
		Methods("GET").
		Path(path).
		Name("GetUserCurrentUserInfo").
		HandlerFunc(getUserFromSessionHandler)

	router.
		Methods("GET").
		Path(path + "/transactions").
		Name("GetLatestTransactions").
		HandlerFunc(getUserTransactionsHandler)

	router.
		Methods("POST").
		Path(path).
		Name("CreateUserInfo").
		HandlerFunc(userPost)

}
Ejemplo n.º 29
0
// PopulateRouter appends all defined routes to a given gorilla mux router.
func PopulateRouter(router *mux.Router) {
	for name, route := range routes {
		h := route.h
		if h == nil {
			h = notImplemented
		}

		router.
			Methods(route.m).
			Path(route.p).
			Name(name).
			Handler(h)
	}
}
Ejemplo n.º 30
0
func addRoutes(routes Routes, router *mux.Router) {
	for _, route := range routes {
		var handler http.Handler

		handler = route.HandlerFunc
		handler = Logger(handler, route.Name)

		router.
			Methods(route.Method).
			Path(route.Pattern).
			Name(route.Name).
			Handler(handler)
	}
}