Created
June 12, 2019 03:17
-
-
Save ridhoperdana/007a1057a9e246cc7c84ec172034e43e to your computer and use it in GitHub Desktop.
Simple code which implement method for add number and minus number.
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
| 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