Ejemplo n.º 1
0
func NewHandler(s api.FluxService, r *mux.Router, logger log.Logger, h metrics.Histogram) http.Handler {
	for method, handlerFunc := range map[string]func(api.FluxService) http.Handler{
		"ListServices":   handleListServices,
		"ListImages":     handleListImages,
		"PostRelease":    handlePostRelease,
		"GetRelease":     handleGetRelease,
		"Automate":       handleAutomate,
		"Deautomate":     handleDeautomate,
		"Lock":           handleLock,
		"Unlock":         handleUnlock,
		"History":        handleHistory,
		"GetConfig":      handleGetConfig,
		"SetConfig":      handleSetConfig,
		"RegisterDaemon": handleRegister,
		"IsConnected":    handleIsConnected,
	} {
		var handler http.Handler
		handler = handlerFunc(s)
		handler = logging(handler, log.NewContext(logger).With("method", method))
		handler = observing(handler, h.With("method", method))

		r.Get(method).Handler(handler)
	}
	return r
}
Ejemplo n.º 2
0
func getURL(router *mux.Router, name string, pairs ...string) string {
	route := router.Get(name)
	if route == nil {
		glog.Fatalf("Couldn't find any route named %s", name)
	}

	routeURL, err := route.URL(pairs...)
	if err != nil {
		glog.Fatalf("Couldn't resolve route %s into a URL", routeURL)
	}

	return routeURL.String()
}
Ejemplo n.º 3
0
func AssignHandlersToUserRoutes(r *mux.Router, c *m.Context, db *sql.DB) *mux.Router {

	userStore := &datastores.UserStore{db}

	r.Get(router.ReadUser).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServeFindUser(userStore))))

	r.Get(router.CreateUser).Handler(m.ServeHTTP(m.ParseRequestBody(new(models.UnauthUser), ServeRegisterUser(userStore))))

	r.Get(router.Login).Handler(m.ServeHTTP(m.ParseRequestBody(new(models.UnauthUser), ServeLogin(userStore))))

	r.Get(router.Logout).Handler(m.AuthenticateToken(c, ServeLogout()))

	return r
}
Ejemplo n.º 4
0
func AssignHandlersToQuestionRoutes(r *mux.Router, c *m.Context, db *sql.DB) *mux.Router {

	questionStore := &datastores.QuestionStore{db}
	//	answerStore := &datastores.AnswerStore{db}

	r.Get(router.ReadPost).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServePostByID(questionStore))))

	r.Get(router.ReadQuestionsByFilter).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServeQuestionsByFilter(questionStore))))

	r.Get(router.ReadSortedQuestions).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServeSortedQuestions(questionStore))))

	r.Get(router.CreateQuestion).Handler(m.AuthenticateToken(c, m.RefreshExpiringToken(ServeSubmitQuestion(questionStore))))

	return r
}
Ejemplo n.º 5
0
func makeURL(endpoint string, router *mux.Router, routeName string, urlParams ...string) (*url.URL, error) {
	if len(urlParams)%2 != 0 {
		panic("urlParams must be even!")
	}

	endpointURL, err := url.Parse(endpoint)
	if err != nil {
		return nil, errors.Wrapf(err, "parsing endpoint %s", endpoint)
	}

	routeURL, err := router.Get(routeName).URL()
	if err != nil {
		return nil, errors.Wrapf(err, "retrieving route path %s", routeName)
	}

	v := url.Values{}
	for i := 0; i < len(urlParams); i += 2 {
		v.Add(urlParams[i], urlParams[i+1])
	}

	endpointURL.Path = path.Join(endpointURL.Path, routeURL.Path)
	endpointURL.RawQuery = v.Encode()
	return endpointURL, nil
}
Ejemplo n.º 6
0
func ServicesHandler(router *mux.Router, w http.ResponseWriter, req *http.Request) {
	url, _ := router.Get("services").URL()
	fmt.Fprintf(w, "Services List Page! Go -> %s", url)
}
Ejemplo n.º 7
0
func HomeHandler(router *mux.Router, w http.ResponseWriter, req *http.Request) {
	url, _ := router.Get("service").URL("service_name", "trolling-and-molling")
	fmt.Fprintf(w, "Home handler! %s", url)
}
Ejemplo n.º 8
0
func MountHandlers(r *mux.Router, ds *api.Services) {
	r.Get(routes.Rankings).HandlerFunc(ListRankingsHandler(ds))
	r.Get(routes.MatchesRun).HandlerFunc(RunMatchesHandler(ds))

	r.Get(routes.Players).HandlerFunc(ListPlayersHandler(ds))
	r.Get(routes.PlayersCreate).HandlerFunc(CreatePlayersHandler(ds))
	r.Get(routes.PlayersDelete).HandlerFunc(DeletePlayersHandler(ds))

	r.Get(routes.Users).HandlerFunc(ListUsersHandler(ds))
	r.Get(routes.UsersCreate).HandlerFunc(CreateUsersHandler(ds))
	r.Get(routes.UsersDelete).HandlerFunc(DeleteUsersHandler(ds))

	r.Get(routes.Games).HandlerFunc(ListDetailsGamesHandler(ds))

	r.Get(routes.GameStates).HandlerFunc(ListGameStatesHandler(ds))
	r.Get(routes.States).HandlerFunc(ListGameStatesHandler(ds)) // alias

	r.Get(routes.APIBaseRoute).Path("/{rest:.*}").HandlerFunc(http.NotFound)
}