Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions internal/flags/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import (

type MemoryRepository struct {
mu sync.RWMutex
flags map[string]*Flag
flags map[string]Flag
}

func NewMemoryRepository() *MemoryRepository {
return &MemoryRepository{
flags: make(map[string]*Flag),
flags: make(map[string]Flag),
}
}

func (r *MemoryRepository) Get(_ context.Context, key string) (*Flag, error) {
func (r *MemoryRepository) Get(_ context.Context, key string) (Flag, error) {
r.mu.RLock()
defer r.mu.RUnlock()

flag, ok := r.flags[key]
if !ok {
return nil, ErrFlagNotFound
return Flag{}, ErrFlagNotFound
}

return flag, nil
}

func (r *MemoryRepository) Create(_ context.Context, flag *Flag) error {
func (r *MemoryRepository) Create(_ context.Context, flag Flag) error {
r.mu.Lock()
defer r.mu.Unlock()

Expand Down
6 changes: 3 additions & 3 deletions internal/flags/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestMemoryRepository_Create(t *testing.T) {
repo := flags.NewMemoryRepository()
ctx := context.Background()

flag := &flags.Flag{
flag := flags.Flag{
Key: "test-flag",
Type: flags.FlagBool,
Enabled: true,
Expand All @@ -34,7 +34,7 @@ func TestMemoryRepository_Create_Duplicate(t *testing.T) {
repo := flags.NewMemoryRepository()
ctx := context.Background()

flag := &flags.Flag{
flag := flags.Flag{
Key: "test-flag",
Type: flags.FlagBool,
Enabled: true,
Expand All @@ -52,7 +52,7 @@ func TestMemoryRepository_Get(t *testing.T) {
repo := flags.NewMemoryRepository()
ctx := context.Background()

flag := &flags.Flag{
flag := flags.Flag{
Key: "test-flag",
Type: flags.FlagBool,
Enabled: true,
Expand Down
4 changes: 2 additions & 2 deletions internal/flags/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ var (
)

type Repository interface {
Get(ctx context.Context, key string) (*Flag, error)
Create(ctx context.Context, flag *Flag) error
Get(ctx context.Context, key string) (Flag, error)
Create(ctx context.Context, flag Flag) error
}
2 changes: 1 addition & 1 deletion internal/flags/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewServiceWithMatcher(repo Repository, matcher RuleMatcher) *Service {
func (s *Service) Create(ctx context.Context, flag Flag) (Flag, error) {
flag.UpdatedAt = time.Now()

if err := s.repo.Create(ctx, &flag); err != nil {
if err := s.repo.Create(ctx, flag); err != nil {
return Flag{}, err
}

Expand Down