diff options
| author | MHSanaei <ho3ein.sanaei@gmail.com> | 2023-05-23 02:13:15 +0300 |
|---|---|---|
| committer | MHSanaei <ho3ein.sanaei@gmail.com> | 2023-05-23 02:13:15 +0300 |
| commit | c38e1e0cfe9fd95f1cd2ed5f6c6cb10bf820b9b6 (patch) | |
| tree | 6bfc79026a489ae9095cc69a1425a9125112cd1c /util/sys/sys_windows.go | |
| parent | f36034541e3b400c44347e6c73f013224697aa6f (diff) | |
a lot of improvement
Diffstat (limited to 'util/sys/sys_windows.go')
| -rw-r--r-- | util/sys/sys_windows.go | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/util/sys/sys_windows.go b/util/sys/sys_windows.go index ef9cdf54..34740ea6 100644 --- a/util/sys/sys_windows.go +++ b/util/sys/sys_windows.go @@ -4,21 +4,27 @@ package sys import ( + "errors" + "github.com/shirou/gopsutil/v3/net" ) -func GetTCPCount() (int, error) { - stats, err := net.Connections("tcp") +func GetConnectionCount(proto string) (int, error) { + if proto != "tcp" && proto != "udp" { + return 0, errors.New("invalid protocol") + } + + stats, err := net.Connections(proto) if err != nil { return 0, err } return len(stats), nil } +func GetTCPCount() (int, error) { + return GetConnectionCount("tcp") +} + func GetUDPCount() (int, error) { - stats, err := net.Connections("udp") - if err != nil { - return 0, err - } - return len(stats), nil + return GetConnectionCount("udp") } |
