Skip to content

Commit 12d009f

Browse files
committed
readme updates
1 parent f682cd5 commit 12d009f

1 file changed

Lines changed: 52 additions & 52 deletions

File tree

README.md

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ See example application [here](https://github.com/featurevisor/featurevisor-exam
5656
In your Go application, install the SDK using Go modules:
5757

5858
```bash
59-
go get github.com/featurevisor/featurevisor-go/sdk
59+
go get github.com/featurevisor/featurevisor-go
6060
```
6161

6262
## Initialization
@@ -70,7 +70,7 @@ import (
7070
"io"
7171
"net/http"
7272

73-
"github.com/featurevisor/featurevisor-go/sdk"
73+
"github.com/featurevisor/featurevisor-go"
7474
)
7575

7676
func main() {
@@ -87,12 +87,12 @@ func main() {
8787
panic(err)
8888
}
8989

90-
var datafileContent sdk.DatafileContent
90+
var datafileContent featurevisor.DatafileContent
9191
if err := datafileContent.FromJSON(string(datafileBytes)); err != nil {
9292
panic(err)
9393
}
9494

95-
f := sdk.CreateInstance(sdk.InstanceOptions{
95+
f := featurevisor.CreateInstance(featurevisor.InstanceOptions{
9696
Datafile: datafileContent,
9797
})
9898
}
@@ -117,7 +117,7 @@ Think of the conditions that you define in your [segments](https://featurevisor.
117117
They are plain maps:
118118

119119
```go
120-
context := sdk.Context{
120+
context := featurevisor.Context{
121121
"userId": "123",
122122
"country": "nl",
123123
// ...other attributes
@@ -132,11 +132,11 @@ You can set context at the time of initialization:
132132

133133
```go
134134
import (
135-
"github.com/featurevisor/featurevisor-go/sdk"
135+
"github.com/featurevisor/featurevisor-go"
136136
)
137137

138-
f := sdk.CreateInstance(sdk.InstanceOptions{
139-
Context: sdk.Context{
138+
f := featurevisor.CreateInstance(featurevisor.InstanceOptions{
139+
Context: featurevisor.Context{
140140
"deviceId": "123",
141141
"country": "nl",
142142
},
@@ -150,7 +150,7 @@ This is useful for values that don't change too frequently and available at the
150150
You can also set more context after the SDK has been initialized:
151151

152152
```go
153-
f.SetContext(sdk.Context{
153+
f.SetContext(featurevisor.Context{
154154
"userId": "234",
155155
})
156156
```
@@ -162,7 +162,7 @@ This will merge the new context with the existing one (if already set).
162162
If you wish to fully replace the existing context, you can pass `true` in second argument:
163163

164164
```go
165-
f.SetContext(sdk.Context{
165+
f.SetContext(featurevisor.Context{
166166
"deviceId": "123",
167167
"userId": "234",
168168
"country": "nl",
@@ -175,7 +175,7 @@ f.SetContext(sdk.Context{
175175
You can optionally pass additional context manually for each and every evaluation separately, without needing to set it to the SDK instance affecting all evaluations:
176176

177177
```go
178-
context := sdk.Context{
178+
context := featurevisor.Context{
179179
"userId": "123",
180180
"country": "nl",
181181
}
@@ -206,7 +206,7 @@ if isEnabled {
206206
You can also pass additional context per evaluation:
207207

208208
```go
209-
isEnabled := f.IsEnabled(featureKey, sdk.Context{
209+
isEnabled := f.IsEnabled(featureKey, featurevisor.Context{
210210
// ...additional context
211211
})
212212
```
@@ -230,7 +230,7 @@ if variation != nil && *variation == "treatment" {
230230
Additional context per evaluation can also be passed:
231231

232232
```go
233-
variation := f.GetVariation(featureKey, sdk.Context{
233+
variation := f.GetVariation(featureKey, featurevisor.Context{
234234
// ...additional context
235235
})
236236
```
@@ -248,7 +248,7 @@ bgColorValue := f.GetVariable("my_feature", variableKey)
248248
Additional context per evaluation can also be passed:
249249

250250
```go
251-
bgColorValue := f.GetVariable("my_feature", variableKey, sdk.Context{
251+
bgColorValue := f.GetVariable("my_feature", variableKey, featurevisor.Context{
252252
// ...additional context
253253
})
254254
```
@@ -272,7 +272,7 @@ f.GetVariableJSON(featureKey, variableKey, context)
272272
You can get evaluations of all features available in the SDK instance:
273273

274274
```go
275-
allEvaluations := f.GetAllEvaluations(sdk.Context{})
275+
allEvaluations := f.GetAllEvaluations(featurevisor.Context{})
276276

277277
fmt.Printf("%+v\n", allEvaluations)
278278
// {
@@ -301,20 +301,20 @@ For the lifecycle of the SDK instance in your application, you can set some feat
301301

302302
```go
303303
import (
304-
"github.com/featurevisor/featurevisor-go/sdk"
304+
"github.com/featurevisor/featurevisor-go"
305305
)
306306

307-
f := sdk.CreateInstance(sdk.InstanceOptions{
307+
f := featurevisor.CreateInstance(featurevisor.InstanceOptions{
308308
Sticky: &StickyFeatures{
309-
"myFeatureKey": sdk.StickyFeature{
309+
"myFeatureKey": featurevisor.StickyFeature{
310310
Enabled: true,
311311
// optional
312-
Variation: &sdk.VariationValue{Value: "treatment"},
312+
Variation: &featurevisor.VariationValue{Value: "treatment"},
313313
Variables: map[string]interface{}{
314314
"myVariableKey": "myVariableValue",
315315
},
316316
},
317-
"anotherFeatureKey": sdk.StickyFeature{
317+
"anotherFeatureKey": featurevisor.StickyFeature{
318318
Enabled: false,
319319
},
320320
},
@@ -328,15 +328,15 @@ Once initialized with sticky features, the SDK will look for values there first
328328
You can also set sticky features after the SDK is initialized:
329329

330330
```go
331-
f.SetSticky(sdk.StickyFeatures{
332-
"myFeatureKey": sdk.StickyFeature{
331+
f.SetSticky(featurevisor.StickyFeatures{
332+
"myFeatureKey": featurevisor.StickyFeature{
333333
Enabled: true,
334-
Variation: &sdk.VariationValue{Value: "treatment"},
334+
Variation: &featurevisor.VariationValue{Value: "treatment"},
335335
Variables: map[string]interface{}{
336336
"myVariableKey": "myVariableValue",
337337
},
338338
},
339-
"anotherFeatureKey": sdk.StickyFeature{
339+
"anotherFeatureKey": featurevisor.StickyFeature{
340340
Enabled: false,
341341
},
342342
}, true) // replace existing sticky features (false by default)
@@ -371,10 +371,10 @@ import (
371371
"io"
372372
"net/http"
373373

374-
"github.com/featurevisor/featurevisor-go/sdk"
374+
"github.com/featurevisor/featurevisor-go"
375375
)
376376

377-
func updateDatafile(f *sdk.Featurevisor, datafileURL string) {
377+
func updateDatafile(f *featurevisor.Featurevisor, datafileURL string) {
378378
ticker := time.NewTicker(5 * time.Minute)
379379
defer ticker.Stop()
380380

@@ -390,7 +390,7 @@ func updateDatafile(f *sdk.Featurevisor, datafileURL string) {
390390
continue
391391
}
392392

393-
var datafileContent sdk.DatafileContent
393+
var datafileContent featurevisor.DatafileContent
394394
if err := datafileContent.FromJSON(string(datafileBytes)); err != nil {
395395
continue
396396
}
@@ -424,28 +424,28 @@ Setting `debug` level will print out all logs, including `info`, `warn`, and `er
424424

425425
```go
426426
import (
427-
"github.com/featurevisor/featurevisor-go/sdk"
427+
"github.com/featurevisor/featurevisor-go"
428428
)
429429

430-
logLevel := sdk.LogLevelDebug
431-
f := sdk.CreateInstance(sdk.InstanceOptions{
430+
logLevel := featurevisor.LogLevelDebug
431+
f := featurevisor.CreateInstance(featurevisor.InstanceOptions{
432432
LogLevel: &logLevel,
433433
})
434434
```
435435

436436
Alternatively, you can also set `logLevel` directly:
437437

438438
```go
439-
logLevel := sdk.LogLevelDebug
440-
f := sdk.CreateInstance(sdk.InstanceOptions{
439+
logLevel := featurevisor.LogLevelDebug
440+
f := featurevisor.CreateInstance(featurevisor.InstanceOptions{
441441
LogLevel: &logLevel,
442442
})
443443
```
444444

445445
You can also set log level from SDK instance afterwards:
446446

447447
```go
448-
f.SetLogLevel(sdk.LogLevelDebug)
448+
f.SetLogLevel(featurevisor.LogLevelDebug)
449449
```
450450

451451
### Handler
@@ -454,17 +454,17 @@ You can also pass your own log handler, if you do not wish to print the logs to
454454

455455
```go
456456
import (
457-
"github.com/featurevisor/featurevisor-go/sdk"
457+
"github.com/featurevisor/featurevisor-go"
458458
)
459459

460-
logger := sdk.NewLogger(sdk.CreateLoggerOptions{
461-
Level: &sdk.LogLevelInfo,
462-
Handler: func(level sdk.LogLevel, message string, details interface{}) {
460+
logger := featurevisor.NewLogger(featurevisor.CreateLoggerOptions{
461+
Level: &featurevisor.LogLevelInfo,
462+
Handler: func(level featurevisor.LogLevel, message string, details interface{}) {
463463
// do something with the log
464464
},
465465
})
466466

467-
f := sdk.CreateInstance(sdk.InstanceOptions{
467+
f := featurevisor.CreateInstance(featurevisor.InstanceOptions{
468468
Logger: logger,
469469
})
470470
```
@@ -480,7 +480,7 @@ You can listen to these events that can occur at various stages in your applicat
480480
### `datafile_set`
481481

482482
```go
483-
unsubscribe := f.On(sdk.EventNameDatafileSet, func(event sdk.Event) {
483+
unsubscribe := f.On(featurevisor.EventNameDatafileSet, func(event featurevisor.Event) {
484484
revision := event.Revision // new revision
485485
previousRevision := event.PreviousRevision
486486
revisionChanged := event.RevisionChanged // true if revision has changed
@@ -507,7 +507,7 @@ compared to the previous datafile content that existed in the SDK instance.
507507
### `context_set`
508508

509509
```go
510-
unsubscribe := f.On(sdk.EventNameContextSet, func(event sdk.Event) {
510+
unsubscribe := f.On(featurevisor.EventNameContextSet, func(event featurevisor.Event) {
511511
replaced := event.Replaced // true if context was replaced
512512
context := event.Context // the new context
513513

@@ -518,7 +518,7 @@ unsubscribe := f.On(sdk.EventNameContextSet, func(event sdk.Event) {
518518
### `sticky_set`
519519

520520
```go
521-
unsubscribe := f.On(sdk.EventNameStickySet, func(event sdk.Event) {
521+
unsubscribe := f.On(featurevisor.EventNameStickySet, func(event featurevisor.Event) {
522522
replaced := event.Replaced // true if sticky features got replaced
523523
features := event.Features // list of all affected feature keys
524524

@@ -568,41 +568,41 @@ A hook is a simple struct with a unique required `Name` and optional functions:
568568

569569
```go
570570
import (
571-
"github.com/featurevisor/featurevisor-go/sdk"
571+
"github.com/featurevisor/featurevisor-go"
572572
)
573573

574-
myCustomHook := &sdk.Hook{
574+
myCustomHook := &featurevisor.Hook{
575575
// only required property
576576
Name: "my-custom-hook",
577577

578578
// rest of the properties below are all optional per hook
579579

580580
// before evaluation
581-
Before: func(options sdk.EvaluateOptions) sdk.EvaluateOptions {
581+
Before: func(options featurevisor.EvaluateOptions) featurevisor.EvaluateOptions {
582582
// update context before evaluation
583583
if options.Context == nil {
584-
options.Context = sdk.Context{}
584+
options.Context = featurevisor.Context{}
585585
}
586586
options.Context["someAdditionalAttribute"] = "value"
587587
return options
588588
},
589589

590590
// after evaluation
591-
After: func(evaluation sdk.Evaluation, options sdk.EvaluateOptions) {
591+
After: func(evaluation featurevisor.Evaluation, options featurevisor.EvaluateOptions) {
592592
if evaluation.Reason == "error" {
593593
// log error
594594
return
595595
}
596596
},
597597

598598
// configure bucket key
599-
BucketKey: func(options sdk.EvaluateOptions) string {
599+
BucketKey: func(options featurevisor.EvaluateOptions) string {
600600
// return custom bucket key
601601
return options.BucketKey
602602
},
603603

604604
// configure bucket value (between 0 and 100,000)
605-
BucketValue: func(options sdk.EvaluateOptions) int {
605+
BucketValue: func(options featurevisor.EvaluateOptions) int {
606606
// return custom bucket value
607607
return options.BucketValue
608608
},
@@ -615,11 +615,11 @@ You can register hooks at the time of SDK initialization:
615615

616616
```go
617617
import (
618-
"github.com/featurevisor/featurevisor-go/sdk"
618+
"github.com/featurevisor/featurevisor-go"
619619
)
620620

621-
f := sdk.CreateInstance(sdk.InstanceOptions{
622-
Hooks: []*sdk.Hook{
621+
f := featurevisor.CreateInstance(featurevisor.InstanceOptions{
622+
Hooks: []*featurevisor.Hook{
623623
myCustomHook,
624624
},
625625
})
@@ -640,7 +640,7 @@ But when using Featurevisor SDK in server-side applications, where a single serv
640640
That's where child instances come in handy:
641641

642642
```go
643-
childF := f.Spawn(sdk.Context{
643+
childF := f.Spawn(featurevisor.Context{
644644
// user or request specific context
645645
"userId": "123",
646646
})

0 commit comments

Comments
 (0)