-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathutil.go
41 lines (35 loc) · 948 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* File: util.go
* Author: Ming Cheng<[email protected]>
*
* Created Date: Thursday, June 23rd 2022, 8:41:25 pm
* Last Modified: Thursday, July 7th 2022, 6:31:41 pm
*
* http://www.opensource.org/licenses/MIT
*/
package socks5lb
import (
log "github.com/sirupsen/logrus"
"os"
"strconv"
"strings"
"time"
)
// GetEnv to get the environment variables from system is not provided return default values
func GetEnv(name, def string) string {
result := os.Getenv(name)
if result == "" {
result = def
}
return strings.TrimSpace(result)
}
// SecFromEnv to get the seconds duration from system environment
func SecFromEnv(name string, defVal uint64) time.Duration {
intervalStr := GetEnv(name, strconv.FormatUint(defVal, 10))
interval, err := strconv.ParseUint(intervalStr, 10, 64)
if err != nil {
log.Debugf("invalid interval %v, reset to 1s", err)
interval = defVal
}
return time.Duration(interval) * time.Second
}