Skip to content

Commit

Permalink
refactor: folder sdk renamed to pkg and README.md updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhi591 committed Aug 2, 2024
1 parent 8f74c0e commit 89a892c
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 43 deletions.
60 changes: 32 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,47 @@ go get "github.com/wingify/vwo-fme-go-sdk"
```go
import vwo "github.com/wingify/vwo-fme-go-sdk"

options := map[string]interface{}{
"sdkKey": "your_sdk_key",
"accountId": "your_account_id",
"gatewayServiceURL": "your_gateway_sercice_url", // http://localhost:3000
}
// init options for vwo client
options := map[string]interface{}{
"sdkKey": "your_sdk_key",
"accountId": "your_account_id",
"gatewayServiceURL": "http://your.host.com:port", // check section - How to Setup Gateway Service - for more details
}

instance, err := vwo.Init(options)
// initialize the vwo client
instance, err := vwo.Init(options)

// Correct JSON string with double quotes
customVars := `{"key": "value"}`
// map for pre-segmentation based on customVariables
customVariables := map[string]interface{}{
"custom_variable_key": "custom_variable_value",
}

// Parse the JSON string into a Go map
var customVariables map[string]interface{}
json.Unmarshal([]byte(customVars), &customVariables)
// Create the user context map
userContext := map[string]interface{}{
"userId": "user_id",
"customVariables": customVariables, // pass customVariables if using customVariables pre-segmentation
"userAgent": "visitor_user_agent",
"ipAddress": "visitor_ip_address",
}

// Create the user context map
userContext := map[string]interface{}{
"userId": "user_id",
"customVariables": customVariables, // pass customVariables if using customVariables pre-segmentation
"userAgent": "visitor_user_agent",
"ipAddress": "visitor_ip_address",
}
// get flag to check if feature is Enabled for the user
getFlag, err := instance.GetFlag("feature_key", userContext)

// get flag to check if feature is Enabled for the user
getFlag, err := instance.GetFlag("feature_key", userContext)
isFeatureEnabled := getFlag.IsEnabled()
getVariableValue := getFlag.GetVariable("variable_key", "default_value")

isFeatureEnabled := getFlag.IsEnabled()
getVariableValue := getFlag.GetVariable("variable_key", "default_value")
// trackEvent to track the conversion for the user
trackEventResponse, err := instance.TrackEvent("event_name", userContext, nil)

// trackEvent to track the conversion for the user
trackEventResponse, err := instance.TrackEvent("event_name", userContext, nil)

// setAttribute to send attribute data for the user
instance.SetAttribute("attribute_key", "attribute_value", userContext)
// setAttribute to send attribute data for the user
instance.SetAttribute("attribute_key", "attribute_value", userContext)

```

## How to Setup Gateway Service
To Setup the Gateway Service, refer to [this](https://hub.docker.com/r/wingifysoftware/vwo-fme-gateway-service)


## Contributing

Please go through our [contributing guidelines](CONTRIBUTING.md)
Expand All @@ -67,4 +71,4 @@ Please go through our [contributing guidelines](CONTRIBUTING.md)

## License

[Apache License, Version 2.0](LICENSE)
[Apache License, Version 2.0](LICENSE)
2 changes: 1 addition & 1 deletion git-hooks/scripts/check-license.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ console.time('Execution time for License and Copyright');
const isSuccess = checkLicenseUtil.checkLicenseAndCopyright({
year: '2024',
author: 'Wingify Software Pvt. Ltd.',
paths: 'sdk/',
paths: 'pkg/',
stoppingCriteria: '\\*\\/',
excludes: [''],
extension: 'go'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions sdk/vwo_builder.go → pkg/vwo_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package sdk
import (
"sync"

"github.com/wingify/vwo-fme-go-sdk/sdk/constants"
"github.com/wingify/vwo-fme-go-sdk/sdk/httpclient"
"github.com/wingify/vwo-fme-go-sdk/sdk/models"
"github.com/wingify/vwo-fme-go-sdk/pkg/constants"
"github.com/wingify/vwo-fme-go-sdk/pkg/httpclient"
"github.com/wingify/vwo-fme-go-sdk/pkg/models"
)

// VWOBuilder is responsible for building and initializing the VWO client.
Expand Down
6 changes: 3 additions & 3 deletions sdk/vwo_client.go → pkg/vwo_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"errors"
"fmt"

"github.com/wingify/vwo-fme-go-sdk/sdk/constants"
"github.com/wingify/vwo-fme-go-sdk/sdk/httpclient"
"github.com/wingify/vwo-fme-go-sdk/sdk/models"
"github.com/wingify/vwo-fme-go-sdk/pkg/constants"
"github.com/wingify/vwo-fme-go-sdk/pkg/httpclient"
"github.com/wingify/vwo-fme-go-sdk/pkg/models"
)

// VWOClient represents the client that interacts with VWO services.
Expand Down
16 changes: 8 additions & 8 deletions vwo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ package vwo
import (
"errors"

"github.com/wingify/vwo-fme-go-sdk/sdk"
"github.com/wingify/vwo-fme-go-sdk/sdk/models"
pkg "github.com/wingify/vwo-fme-go-sdk/pkg"
"github.com/wingify/vwo-fme-go-sdk/pkg/models"
)

var instance *sdk.VWOClient
var instance *pkg.VWOClient

// SetInstance configures and builds the VWO instance using the provided options.
// It initializes the VWO client with the given options and fetches the settings.
func SetInstance(options models.VWOInitOptions) (*sdk.VWOClient, error) {
vwoBuilder := sdk.NewVWOBuilder(options)
func SetInstance(options models.VWOInitOptions) (*pkg.VWOClient, error) {
vwoBuilder := pkg.NewVWOBuilder(options)
vwoBuilder.InitClient()
settings := vwoBuilder.GetSettings(false)
return sdk.NewVWOClient(settings, options), nil
return pkg.NewVWOClient(settings, options), nil
}

// GetInstance gets the singleton instance of VWO.
// It returns the VWO client instance if it has been initialized.
func GetInstance() *sdk.VWOClient {
func GetInstance() *pkg.VWOClient {
return instance
}

// Init initializes the VWO instance with the provided options.
// It validates the options and sets up the VWO client instance.
func Init(options map[string]interface{}) (*sdk.VWOClient, error) {
func Init(options map[string]interface{}) (*pkg.VWOClient, error) {

if options["sdkKey"] == nil || options["sdkKey"].(string) == "" {
return nil, errors.New("sdkKey is required to initialize VWO. Please provide the sdkKey in the options")
Expand Down

0 comments on commit 89a892c

Please sign in to comment.