2019-03-19 22:25:49 +01:00
package common
// Misc utils
import (
2020-08-23 17:54:01 +02:00
"os"
"path/filepath"
2019-03-19 22:25:49 +01:00
"regexp"
)
2019-11-29 02:04:12 +01:00
var usernameRegex * regexp . Regexp = regexp . MustCompile ( ` ^[0-9a-zA-Z_-]*[a-zA-Z0-9]+[0-9a-zA-Z_-]*$ ` )
const InvalidNameError string = ` Invalid name.<br />Name must be between 3 and 36 characters in length; contain only numbers, letters, underscores or dashes; and contain at least one number or letter.<br />Names cannot contain spaces. `
2019-03-19 22:25:49 +01:00
2019-03-20 03:56:01 +01:00
// IsValidName checks that name is within the correct ranges, follows the regex defined
// and is not a valid color name
2019-03-19 22:25:49 +01:00
func IsValidName ( name string ) bool {
2019-03-20 03:56:01 +01:00
return 3 <= len ( name ) && len ( name ) <= 36 &&
2019-03-24 20:15:28 +01:00
usernameRegex . MatchString ( name )
2019-03-19 22:25:49 +01:00
}
2020-08-23 17:54:01 +02:00
// Return the absolut directory containing the MovieNight binary
func RunPath ( ) string {
ex , er := os . Executable ( )
if er != nil {
panic ( er )
}
return filepath . Dir ( ex )
}