Skip to content

Instantly share code, notes, and snippets.

@juusechec
Created March 6, 2021 19:28
Show Gist options
  • Save juusechec/9a6a43586b0fa97c0cdae46e655d2034 to your computer and use it in GitHub Desktop.
Save juusechec/9a6a43586b0fa97c0cdae46e655d2034 to your computer and use it in GitHub Desktop.
GO NumericInput example with rune input
package main
import "fmt"
import "unicode"
type UserInput interface {
Add(rune)
GetValue() string
}
type NumericInput struct {
input string
}
func (ni *NumericInput) Add(input rune) {
if unicode.IsDigit(input) {
ni.input += string(input)
}
}
func (ni *NumericInput) GetValue() string {
return ni.input
}
func main() {
var input UserInput = &NumericInput{}
input.Add(rune('1'))
input.Add(rune('a'))
input.Add(rune('0'))
fmt.Println(input.GetValue())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment