mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-11 15:21:02 +00:00
wrap regexp in function
This commit is contained in:
parent
28580fd354
commit
4e31d02979
3 changed files with 18 additions and 7 deletions
6
db.go
6
db.go
|
|
@ -49,9 +49,9 @@ type DB struct {
|
|||
|
||||
// NewDB returns a new instance of DB.
|
||||
func NewDB(path, name string) (*DB, error) {
|
||||
validName := Exp.FindStringSubmatchIndex(name)
|
||||
if len(validName) == 0 {
|
||||
return nil, ErrName
|
||||
err := ValidateName(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DB{
|
||||
|
|
|
|||
6
frame.go
6
frame.go
|
|
@ -47,9 +47,9 @@ type Frame struct {
|
|||
|
||||
// NewFrame returns a new instance of frame.
|
||||
func NewFrame(path, db, name string) (*Frame, error) {
|
||||
validName := Exp.FindStringSubmatchIndex(name)
|
||||
if len(validName) == 0 {
|
||||
return nil, ErrName
|
||||
err := ValidateName(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Frame{
|
||||
|
|
|
|||
13
pilosa.go
13
pilosa.go
|
|
@ -28,7 +28,8 @@ var (
|
|||
)
|
||||
|
||||
// Regular expression to valuate db and frame's name
|
||||
var Exp = regexp.MustCompile(`^([a-z0-9._-]{1,64}$)`)
|
||||
// Todo: remove . when frame doesn't require . for topN
|
||||
var nameRegexp = 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.
|
||||
|
|
@ -82,3 +83,13 @@ 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 {
|
||||
validName := nameRegexp.Match([]byte(name))
|
||||
if validName == false{
|
||||
return ErrName
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue