fix review

This commit is contained in:
Linh Vo 2017-03-06 11:03:17 -06:00
parent 69cfdb0df9
commit c6a502efed
4 changed files with 10 additions and 27 deletions

View file

@ -194,11 +194,6 @@ func (c *Client) ExecuteQuery(ctx context.Context, db, query string, allowRedire
return nil, ErrQueryRequired
}
er := ValidateName(db)
if er != nil {
return nil, ErrName
}
// Encode query request.
buf, err := proto.Marshal(&internal.QueryRequest{
DB: db,
@ -255,11 +250,6 @@ func (c *Client) ExecutePQL(ctx context.Context, db, query string) (interface{},
}.Encode(),
}
er := ValidateName(db)
if er != nil {
return nil, ErrName
}
req, err := http.NewRequest("POST", u.String(), bytes.NewReader([]byte(query)))
if err != nil {
return nil, err

6
db.go
View file

@ -49,9 +49,9 @@ type DB struct {
// NewDB returns a new instance of DB.
func NewDB(path, name string) (*DB, error) {
err := ValidateName(name)
if err != nil {
return nil, err
validName := Exp.FindStringSubmatchIndex(name)
if len(validName) == 0 {
return nil, ErrName
}
return &DB{

View file

@ -47,9 +47,9 @@ type Frame struct {
// NewFrame returns a new instance of frame.
func NewFrame(path, db, name string) (*Frame, error) {
err := ValidateName(name)
if err != nil {
return nil, err
validName := Exp.FindStringSubmatchIndex(name)
if len(validName) == 0 {
return nil, ErrName
}
return &Frame{

View file

@ -20,13 +20,16 @@ var (
ErrFrameNotFound = errors.New("frame not found")
// ErrFrameRequired is returned when no frame is specified.
ErrName = errors.New("name restricted to [a-z0-9_-.]")
ErrName = errors.New("name restricted to [a-z0-9_-]")
// ErrFragmentNotFound is returned when a fragment does not exist.
ErrFragmentNotFound = errors.New("fragment not found")
ErrQueryRequired = errors.New("query required")
)
// Regular expression to valuate db and frame's name
var Exp = regexp.MustCompile(`^([a-z0-9._-]{1,64}$)`)
// Profile represents vertical column in a database.
// A profile can have a set of attributes attached to it.
type Profile struct {
@ -79,13 +82,3 @@ func decodeProfile(pb *internal.Profile) *Profile {
// TimeFormat is the go-style time format used to parse string dates.
const TimeFormat = "2006-01-02T15:04"
// Restrict name using regex
func ValidateName(name string) error {
expr := regexp.MustCompile(`^([a-z0-9._-]{1,64}$)`)
validName := expr.FindStringSubmatchIndex(name)
if len(validName) == 0 {
return ErrName
}
return nil
}