2

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)
}
6
  • Did you recently build helpers? cd src/helper ; go build Commented Aug 9, 2014 at 4:19
  • yes before building src/models Commented Aug 9, 2014 at 4:20
  • when i do it manually it builds well, but i made a Makefile it does the same but doesn't work, any idea? GOCMD=go GOBUILD=$(GOCMD) build MODELS_DIR=src/models HELPERS_DIR=src/helpers all: model helper ${GOBUILD} model: $(MAKE) -C $(MODELS_DIR) helper: $(MAKE) -C $(HELPERS_DIR) Commented Aug 9, 2014 at 4:27
  • Could you inverse the order of 'all' in your Makefile? all: helper model Commented Aug 9, 2014 at 4:29
  • 1
    What is MAKE? Could you simply call go build, as in this Makefile? gist.github.com/dnishimura/2961173 Commented Aug 9, 2014 at 4:39

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

men, i'm having the same problem making the binary executable, if i go build PACKAGE works, but when i go build the main package says models/product.go:53: undefined: helpers.ProductNameValidator here is the command i used to build go build helpers &&\ go build models &&\ go build handlers &&\ go build db &&\ go build -o ciudad-gourmet main.go

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.