我有以下包 src/helpers,但是當我將它導入到不同的包中時,導出的唯一函數是 EmailValidator,但不是其他函數,它們都以 Mayus 開頭,所以我不知道發生了什么。謝謝package modelsimport ( "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: 未定義: helpers.UniqueNamesValidator但func FindByEmail(email *string) (*User, error) { if email == nil || len(*email) == 0 || !helpers.EmailValidator(*email) { return nil, errors.New("Invalid Email") } ... }效果很好這是源代碼。package helpersimport ( "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 回答

湖上湖
TA貢獻2003條經驗 獲得超2個贊
如本 Makefile 所示,并在評論中確認,更好的定義是:
GOCMD=go
GOBUILD=$(GOCMD)
build all: $(GOBUILD) $(HELPERS_DIR) $(GOBUILD) $(MODELS_DIR)
- 1 回答
- 0 關注
- 235 瀏覽
添加回答
舉報
0/150
提交
取消