Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,37 @@ import (
"fmt"
"time"

"github.com/optimizely/go-sdk"
"github.com/optimizely/go-sdk/pkg/client"
"github.com/optimizely/go-sdk/pkg/entities"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is no longer used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky because when imported, we import the namespace "optimizely", which is the package name and we would be referring to this import via optimizely.xxx

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @mikecdavis is talking about "github.com/optimizely/go-sdk/pkg/entities", this is unused.

"github.com/optimizely/go-sdk/pkg/event"
"github.com/optimizely/go-sdk/pkg/events"
"github.com/optimizely/go-sdk/pkg/logging"
)

func main() {
sdkKey := "4SLpaJA1r1pgE6T2CoMs9q"
logging.SetLogLevel(logging.LogLevelDebug)
user := entities.UserContext{
ID: "mike ng",
Attributes: map[string]interface{}{

/************* Simple usage ********************/

user := optimizely.UserContext(
"mike ng",
map[string]interface{}{
"country": "Unknown",
"likes_donuts": true,
},
}
)
optimizelyClient, _ := optimizely.Client(sdkKey)
enabled, _ := optimizelyClient.IsFeatureEnabled("mutext_feat", user)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting an error below because we define enabled here.

fmt.Printf("Is feature enabled? %v\n", enabled)

/************* StaticClient ********************/

optimizelyFactory := &client.OptimizelyFactory{
SDKKey: sdkKey,
}

/************* StaticClient ********************/

optimizelyClient, err := optimizelyFactory.StaticClient()
optimizelyClient, err = optimizelyFactory.StaticClient()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err is no longer defined.


if err != nil {
fmt.Printf("Error instantiating client: %s", err)
Expand All @@ -42,6 +50,7 @@ func main() {
fmt.Println()
optimizelyClient.Close() // user can close dispatcher
fmt.Println()

/************* Client ********************/

optimizelyFactory = &client.OptimizelyFactory{
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
* limitations under the License. *
***************************************************************************/

package main
package optimizely
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can't mix the "application" (e.g. "package main") with an importable package. Perhaps we just remove this CLI and move it into the sidedoor repo instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that would make it simpler.


import "github.com/optimizely/go-sdk/cmd"

// This is used to execute the command-line tool when running the `go-sdk` command from the command-line.
func main() {
cmd.Execute()
}
38 changes: 38 additions & 0 deletions optimizely.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/****************************************************************************
* Copyright 2019, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/

package optimizely

import (
"github.com/optimizely/go-sdk/pkg/client"
"github.com/optimizely/go-sdk/pkg/entities"
)

// Client returns an OptimizelyClient instantitated with the given key and options
func Client(sdkKey string, options ...client.OptionFunc) (*client.OptimizelyClient, error) {
factory := &client.OptimizelyFactory{
SDKKey: sdkKey,
}
return factory.Client(options...)
}

// UserContext is a helper method for creating a user context
func UserContext(userID string, attributes map[string]interface{}) entities.UserContext {
return entities.UserContext{
ID: userID,
Attributes: attributes,
}
}
2 changes: 1 addition & 1 deletion pkg/client/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type OptimizelyFactory struct {
overrideStore decision.ExperimentOverrideStore
}

// OptionFunc is a type to a proper func
// OptionFunc is used to provide custom client configuration to the OptimizelyFactory
type OptionFunc func(*OptimizelyFactory)

// Client gets client and sets some parameters
Expand Down