Skip to content

Instantly share code, notes, and snippets.

@ridhoperdana
Created June 12, 2019 03:17
Show Gist options
  • Select an option

  • Save ridhoperdana/007a1057a9e246cc7c84ec172034e43e to your computer and use it in GitHub Desktop.

Select an option

Save ridhoperdana/007a1057a9e246cc7c84ec172034e43e to your computer and use it in GitHub Desktop.
Simple code which implement method for add number and minus number.
package calculator
import "context"
type operation struct {
SavedNumber int
}
// Add is method implementation to add number with saved number
func (s *operation) Add(ctx context.Context, number int) (int, error) {
s.SavedNumber = s.SavedNumber + number
return s.SavedNumber, nil
}
// Minus is method implementation to minus number with saved number
func (s *operation) Minus(ctx context.Context, number int) (int, error) {
s.SavedNumber = s.SavedNumber - number
return s.SavedNumber, nil
}
// InitOperation is constructor to initialize operation
func InitOperation() *operation {
return &operation{
SavedNumber: 0,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment