Golang未定义的函数

时间:2014-08-09 04:12:38

标签: go

我有以下包src / helpers但是当我在另一个包中导入它时,导出的唯一功能是EmailValidator,而不是其他的,所有这些都以Mayus开头,所以我不知道&#39发生了。感谢

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

func FindByEmail(email *string) (*User, error) {
    if email == nil || len(*email) == 0 || !helpers.EmailValidator(*email) {
            return nil, errors.New("Invalid Email")
    }
 ...
 }

运作良好

这是源代码。

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)
}

1 个答案:

答案 0 :(得分:1)

作为illustrated in this Makefile,并确认in the comments,更好的定义是:

GOCMD=go 
GOBUILD=$(GOCMD) 
build all: $(GOBUILD) $(HELPERS_DIR) $(GOBUILD) $(MODELS_DIR)