Skip to content

Instantly share code, notes, and snippets.

@azhuox

azhuox/block1.go Secret

Created December 2, 2020 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azhuox/be139a402252b286d0f90336e1244366 to your computer and use it in GitHub Desktop.
Save azhuox/be139a402252b286d0f90336e1244366 to your computer and use it in GitHub Desktop.
package encapsulationexample
// SimpleCounter - a simple counter.
type SimpleCounter struct {
counter int
}
// NewCounter - creates a new counter instance.
func NewCounter() *SimpleCounter {
return &SimpleCounter{
counter: 0,
}
}
// N - return current counter's value.
func (c *SimpleCounter) N() int { return c.counter }
// Increment - increases the counter by 1 without considering the risk of race condition.
func (c *SimpleCounter) Increment() { c.counter++ }
// Reset - resets the counter.
func (c *SimpleCounter) Reset() { c.counter = 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment