コード例 #1
0
ファイル: main.go プロジェクト: andrewsmedina/features
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
ファイル: api.go プロジェクト: andrewsmedina/features
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
}