Reputation: 677
I have the following package src/helpers but when i import it in a different package the only function exported is EmailValidator, but not the other ones, all of them begin with Mayus so i don't know what's happening. thanks
package models
import (
"helpers"
...
)
func FindByUsername(username *string) (*User, error) {
if username == nil || len(*username) == 0 ||
!helpers.UniqueNamesValidator(*username) {
return nil, errors.New("Invalid Username")
}
...
}
src/models/user.go:88: undefined: helpers.UniqueNamesValidator
but
func FindByEmail(email *string) (*User, error) {
if email == nil || len(*email) == 0 || !helpers.EmailValidator(*email) {
return nil, errors.New("Invalid Email")
}
...
}
works well
here is the source code.
package helpers
import (
"regexp"
)
const (
email_key = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*"
email_domain = "@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
)
func EmailValidator(email string) bool {
pattern := regexp.MustCompile(email_key + email_domain)
return pattern.MatchString(email)
}
func UserNamesValidator(name string) bool {
pattern := regexp.MustCompile(`\A([ña-zA-ZÑ]{3,16} {0,1}){1,3}\z`)
return pattern.MatchString(name)
}
func UniqueNamesValidator(unique_name string) bool {
pattern := regexp.MustCompile(`\A\w{4,10}\z`)
return pattern.MatchString(unique_name)
}
func ProductNameValidator(p_name string) bool {
pattern := regexp.MustCompile(`\A(\w|\s){4,30}\z`)
return pattern.MatchString(p_name)
}
func TextOnlyValidator(text string) bool {
pattern := regexp.MustCompile(`\A(\w+|\s)+\z`)
return pattern.MatchString(text)
}
Upvotes: 2
Views: 5399
Reputation: 1324318
As illustrated in this Makefile, and confirmed in the comments, a better definition would be:
GOCMD=go
GOBUILD=$(GOCMD)
build all: $(GOBUILD) $(HELPERS_DIR) $(GOBUILD) $(MODELS_DIR)
Upvotes: 1