I'm trying to create a new Go type that's based on string
but is required to match a pattern (Slack username, e.g. @ben
).
When used, the type would look something like:
var user SlackUser
user = SlackUser("@ben")
fmt.Println(user) //This should print: @ben
If it matches the pattern, NewSlackUser
will work. If it doesn't, it will throw an error.
The pattern to match, which is based on this, is:
^@[a-z0-9][a-z0-9._-]*$
(I'm very new to Go, so any correction to my approach is much appreciated)