mirror of
https://github.com/cristicalin/synology-csi.git
synced 2026-05-08 05:52:38 +00:00
Initial commit
This commit is contained in:
33
pkg/utils/utils.go
Normal file
33
pkg/utils/utils.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2021 Synology Inc.
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const UNIT_GB = 1024 * 1024 * 1024
|
||||
|
||||
func StringToBoolean(value string) bool {
|
||||
value = strings.ToLower(value)
|
||||
return value == "yes" || value == "true" || value == "1"
|
||||
}
|
||||
|
||||
// Haven't supported IPv6 yet.
|
||||
func LookupIPv4(name string) ([]string, error) {
|
||||
ips, _ := net.LookupIP(name)
|
||||
|
||||
retIps := []string{}
|
||||
for _, ip := range ips {
|
||||
if ipv4 := ip.To4(); ipv4 != nil {
|
||||
retIps = append(retIps, ipv4.String())
|
||||
}
|
||||
}
|
||||
if len(retIps) > 0 {
|
||||
return retIps, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("Failed to LookupIPv4 by local resolver for: %s", name)
|
||||
}
|
||||
Reference in New Issue
Block a user