Skip to content

Commit

Permalink
refactor: Removing pointer when not necessary (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
ViBiOh authored Apr 7, 2020
1 parent 950acb0 commit 8d7c608
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pkg/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (a app) Unmarshal(content []byte) (interface{}, error) {
return nil, err
}

return &o, nil
return o, nil
}

// List Targets
Expand Down Expand Up @@ -72,18 +72,18 @@ func (a app) Get(ctx context.Context, ID uint64) (interface{}, error) {
return nil, fmt.Errorf("unable to get target: %w", err)
}

return &target, nil
return target, nil
}

// Create Target
func (a app) Create(ctx context.Context, o interface{}) (item interface{}, err error) {
var target *Target
var target Target
target, err = getTargetFromItem(ctx, o)
if err != nil {
return
}

err = a.saveTarget(target, nil)
err = a.saveTarget(&target, nil)
if err != nil {
err = fmt.Errorf("unable to create target: %w", err)
return
Expand All @@ -96,13 +96,13 @@ func (a app) Create(ctx context.Context, o interface{}) (item interface{}, err e

// Update Target
func (a app) Update(ctx context.Context, o interface{}) (item interface{}, err error) {
var target *Target
var target Target
target, err = getTargetFromItem(ctx, o)
if err != nil {
return
}

err = a.saveTarget(target, nil)
err = a.saveTarget(&target, nil)
if err != nil {
err = fmt.Errorf("unable to update target: %w", err)

Expand All @@ -116,13 +116,13 @@ func (a app) Update(ctx context.Context, o interface{}) (item interface{}, err e

// Delete Target
func (a app) Delete(ctx context.Context, o interface{}) (err error) {
var target *Target
var target Target
target, err = getTargetFromItem(ctx, o)
if err != nil {
return
}

err = a.deleteTarget(*target, nil)
err = a.deleteTarget(target, nil)
if err != nil {
err = fmt.Errorf("unable to delete target: %w", err)
}
Expand Down Expand Up @@ -158,10 +158,10 @@ func (a app) Check(ctx context.Context, old, new interface{}) []crud.Error {
return errors
}

func getTargetFromItem(ctx context.Context, o interface{}) (*Target, error) {
item, ok := o.(*Target)
func getTargetFromItem(ctx context.Context, o interface{}) (Target, error) {
item, ok := o.(Target)
if !ok {
return nil, errors.New("item is not a Target")
return item, errors.New("item is not a Target")
}

return item, nil
Expand Down

0 comments on commit 8d7c608

Please sign in to comment.