mirror of
https://github.com/aykhans/movier.git
synced 2025-07-19 16:54:00 +00:00
Rewritten in go and python
This commit is contained in:
11
server/pkg/utils/env.go
Normal file
11
server/pkg/utils/env.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import "os"
|
||||
|
||||
func GetEnv(key, default_ string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return default_
|
||||
}
|
||||
return value
|
||||
}
|
16
server/pkg/utils/file.go
Normal file
16
server/pkg/utils/file.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package utils
|
||||
|
||||
import "os"
|
||||
|
||||
func MakeDirIfNotExist(path string) error {
|
||||
return os.MkdirAll(path, os.ModePerm)
|
||||
}
|
||||
|
||||
func IsDirExist(path string) (bool, error) {
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return true, nil
|
||||
} else if !os.IsNotExist(err) {
|
||||
return false, err
|
||||
}
|
||||
return false, nil
|
||||
}
|
20
server/pkg/utils/validation.go
Normal file
20
server/pkg/utils/validation.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func IsValidPath(path string) bool {
|
||||
return filepath.IsAbs(path)
|
||||
}
|
||||
|
||||
func IsUint32(value int) bool {
|
||||
return value >= 0 && value <= math.MaxUint32
|
||||
}
|
||||
|
||||
func IsInt(value string) bool {
|
||||
_, err := strconv.Atoi(value)
|
||||
return err == nil
|
||||
}
|
Reference in New Issue
Block a user