Пример #1
0
func main() {
	Features := features.New(memory.New())

	feature := engine.FeatureFlag{
		Key:     "Feature X",
		Enabled: false,
		Users:   []*engine.User{&engine.User{Id: "*****@*****.**"}},
	}
	Features.Save(feature)

	active, _ := Features.IsEnabled("Feature X")
	fmt.Printf("Is `Feature X` enabled? %t \n", active)

	deactive, _ := Features.IsDisabled("Feature X")
	fmt.Printf("Is `Feature X` disabled? %t \n", deactive)

	Features.With("Feature X", func() {
		fmt.Println("`Feature X` is enabled!")
	})

	Features.Without("Feature X", func() {
		fmt.Println("`Feature X` is disabled!")
	})

	fmt.Printf("Does `[email protected]` have access to `Feature X`? %t \n", Features.UserHasAccess("Feature X", "*****@*****.**"))

}
Пример #2
0
func (s *S) SetUpTest(c *C) {
	s.Features = features.New(memory.New())
}
Пример #3
0
func NewApi(ng engine.Engine) *Api {
	api := &Api{router: NewRouter(), ng: ng}

	api.router.NotFoundHandler(http.HandlerFunc(api.notFoundHandler))
	api.router.AddHandler(RouterArguments{Path: "/", Methods: []string{"GET"}, Handler: homeHandler})
	ctx := context.Background()

	ffs := features.New(api.ng)

	createHandler := httptransport.NewServer(
		ctx,
		CreateEndpoint(ffs),
		decodeFeatureFlagRequest,
		encodeResponse,
		httptransport.ServerErrorEncoder(handleErrorEncoder),
	)
	api.router.AddHandler(RouterArguments{Path: "/features", Methods: []string{"POST"}, HandlerNormal: createHandler})

	updateHandler := httptransport.NewServer(
		ctx,
		UpdateEndpoint(ffs),
		decodeFeatureFlagRequest,
		encodeResponse,
		httptransport.ServerErrorEncoder(handleErrorEncoder),
	)
	api.router.AddHandler(RouterArguments{Path: "/features/{feature_key}", Methods: []string{"PUT"}, HandlerNormal: updateHandler})

	deleteHandler := httptransport.NewServer(
		ctx,
		DeleteEndpoint(ffs),
		decodeFeatureFlagQueryString,
		encodeResponse,
		httptransport.ServerErrorEncoder(handleErrorEncoder),
	)
	api.router.AddHandler(RouterArguments{Path: "/features/{feature_key}", Methods: []string{"DELETE"}, HandlerNormal: deleteHandler})

	findHandler := httptransport.NewServer(
		ctx,
		FindEndpoint(ffs),
		decodeFeatureFlagQueryString,
		encodeResponse,
		httptransport.ServerErrorEncoder(handleErrorEncoder),
	)
	api.router.AddHandler(RouterArguments{Path: "/features/{feature_key}", Methods: []string{"GET"}, HandlerNormal: findHandler})

	listHandler := httptransport.NewServer(
		ctx,
		ListEndpoint(ffs),
		decodeFeatureFlagQueryString,
		encodeResponse,
		httptransport.ServerErrorEncoder(handleErrorEncoder),
	)
	api.router.AddHandler(RouterArguments{Path: "/features", Methods: []string{"GET"}, HandlerNormal: listHandler})

	validateHandler := httptransport.NewServer(
		ctx,
		ValidateEndpoint(ffs),
		decodeValidationRequest,
		encodeResponse,
		httptransport.ServerErrorEncoder(handleErrorEncoder),
	)
	api.router.AddHandler(RouterArguments{Path: "/features", Methods: []string{"PUT"}, HandlerNormal: validateHandler})

	return api
}