-
Notifications
You must be signed in to change notification settings - Fork 2
feat: create structs representing Featurevisor instance and config manager #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
1e9y
wants to merge
3
commits into
featurevisor:main
Choose a base branch
from
1e9y:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# Local IDE configuration | ||
.idea/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package config | ||
|
||
// Config represents a parsed datafile config. | ||
type Config interface { | ||
GetDatafile() []byte | ||
GetRevision() string | ||
// ...rest of the methods | ||
} | ||
|
||
// ConfigManager represents a configuration manager that reads and holds datafile config. | ||
type ConfigManager interface { | ||
GetConfig() (Config, error) | ||
Sync() error | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"sync" | ||
) | ||
|
||
type StaticConfigManager struct { | ||
datafileURL string | ||
datafile []byte | ||
client *http.Client | ||
config Config | ||
lock sync.Mutex | ||
logger interface{} | ||
} | ||
|
||
func (configManager *StaticConfigManager) GetConfig() (Config, error) { | ||
configManager.lock.Lock() | ||
defer configManager.lock.Unlock() | ||
|
||
return configManager.config, nil | ||
} | ||
|
||
func (configManager *StaticConfigManager) Sync() error { | ||
configManager.lock.Lock() | ||
defer configManager.lock.Unlock() | ||
|
||
url := configManager.datafileURL | ||
datafile, err := http.Get(url) | ||
if err != nil { | ||
return fmt.Errorf("error while loading datafile: %w", err) | ||
} | ||
|
||
// Read the body of the response into a byte array | ||
defer datafile.Body.Close() | ||
body, err := io.ReadAll(datafile.Body) | ||
if err != nil { | ||
return fmt.Errorf("error while reading datafile: %w", err) | ||
} | ||
|
||
configManager.datafile = body | ||
return nil | ||
} | ||
|
||
func NewStaticConfigManager(datafileURL string) *StaticConfigManager { | ||
return &StaticConfigManager{ | ||
datafileURL: datafileURL, | ||
client: http.DefaultClient, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/featurevisor/featurevisor-go" | ||
) | ||
|
||
func main() { | ||
datafileURL := "https://featurevisor.com/datafile.yml" | ||
|
||
instance, err := featurevisor.NewInstance(datafileURL) | ||
if err != nil { | ||
fmt.Printf("Error creating Featurevisor: %s\n", err) | ||
return | ||
} | ||
|
||
revision := instance.GetRevision() | ||
fmt.Printf("Featurevisor datafile revision: %s\n", revision) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package featurevisor | ||
|
||
import "github.com/featurevisor/featurevisor-go/instance" | ||
|
||
func NewInstance(datafileURL string) (*instance.Instance, error) { | ||
factory := &instance.Factory{ | ||
DatafileURL: datafileURL, | ||
} | ||
|
||
return factory.NewInstance() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package instance | ||
|
||
import "github.com/featurevisor/featurevisor-go/config" | ||
|
||
type Factory struct { | ||
DatafileURL string | ||
|
||
logger interface{} | ||
} | ||
|
||
// Instance creates a new Featurevisor instance with passed datafile URL. | ||
func (factory *Factory) NewInstance() (*Instance, error) { | ||
configManager := config.NewStaticConfigManager(factory.DatafileURL) | ||
|
||
instance := &Instance{ | ||
ConfigManager: configManager, | ||
} | ||
return instance, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package instance | ||
|
||
import "github.com/featurevisor/featurevisor-go/config" | ||
|
||
type Instance struct { | ||
ConfigManager config.ConfigManager | ||
|
||
logger interface{} | ||
} | ||
|
||
// GetRevision returns the revision of the datafile | ||
func (instance *Instance) GetRevision() string { | ||
return "" | ||
} | ||
|
||
// GetBucketKey returns the bucket key for the given feature name | ||
func (instance *Instance) GetBucketKey(featureName string) string { | ||
return "" | ||
} | ||
|
||
// Enabled returns true if the feature is enabled | ||
func (instance *Instance) Enabled(featureName string) bool { | ||
return false | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idea is to keep the interfaces/API as similar as the original JS SDK: https://github.com/featurevisor/featurevisor/tree/main/packages/sdk/src
this is how we are approaching Swift and Kotlin SDKs as well, helping keep it relatively easy to port bug fixes everywhere continuously.