Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Canread
Gopsutil
提交
5d0724f4
G
Gopsutil
项目概览
Canread
/
Gopsutil
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gopsutil
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5d0724f4
编写于
8月 18, 2021
作者:
V
Ville Skyttä
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Comment convention fixes
上级
803cea9d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
11 deletion
+11
-11
internal/common/common.go
internal/common/common.go
+9
-9
internal/common/common_linux.go
internal/common/common_linux.go
+2
-2
未找到文件。
internal/common/common.go
浏览文件 @
5d0724f4
...
...
@@ -94,7 +94,7 @@ func (i FakeInvoke) CommandWithContext(ctx context.Context, name string, arg ...
var
ErrNotImplementedError
=
errors
.
New
(
"not implemented yet"
)
// ReadFile reads contents from a file
// ReadFile reads contents from a file
.
func
ReadFile
(
filename
string
)
(
string
,
error
)
{
content
,
err
:=
ioutil
.
ReadFile
(
filename
)
...
...
@@ -111,7 +111,7 @@ func ReadLines(filename string) ([]string, error) {
return
ReadLinesOffsetN
(
filename
,
0
,
-
1
)
}
// ReadLines reads contents from file and splits them by new line.
// ReadLines
OffsetN
reads contents from file and splits them by new line.
// The offset tells at which line number to start.
// The count determines the number of lines to read (starting from offset):
// n >= 0: at most n lines
...
...
@@ -224,31 +224,31 @@ func ReadInts(filename string) ([]int64, error) {
return
ret
,
nil
}
//
Parse Hex to uint32 without error
//
HexToUint32 parses Hex to uint32 without error.
func
HexToUint32
(
hex
string
)
uint32
{
vv
,
_
:=
strconv
.
ParseUint
(
hex
,
16
,
32
)
return
uint32
(
vv
)
}
//
Parse to int32 without error
//
mustParseInt32 parses to int32 without error.
func
mustParseInt32
(
val
string
)
int32
{
vv
,
_
:=
strconv
.
ParseInt
(
val
,
10
,
32
)
return
int32
(
vv
)
}
//
Parse to uint64 without error
//
mustParseUint64 parses to uint64 without error.
func
mustParseUint64
(
val
string
)
uint64
{
vv
,
_
:=
strconv
.
ParseInt
(
val
,
10
,
64
)
return
uint64
(
vv
)
}
//
Parse to Float64 without error
//
mustParseFloat64 parses to Float64 without error.
func
mustParseFloat64
(
val
string
)
float64
{
vv
,
_
:=
strconv
.
ParseFloat
(
val
,
64
)
return
vv
}
// StringsHas checks the target string slice contains src or not
// StringsHas checks the target string slice contains src or not
.
func
StringsHas
(
target
[]
string
,
src
string
)
bool
{
for
_
,
t
:=
range
target
{
if
strings
.
TrimSpace
(
t
)
==
src
{
...
...
@@ -258,7 +258,7 @@ func StringsHas(target []string, src string) bool {
return
false
}
// StringsContains checks the src in any string of the target string slice
// StringsContains checks the src in any string of the target string slice
.
func
StringsContains
(
target
[]
string
,
src
string
)
bool
{
for
_
,
t
:=
range
target
{
if
strings
.
Contains
(
t
,
src
)
{
...
...
@@ -308,7 +308,7 @@ func PathExists(filename string) bool {
return
false
}
//GetEnv retrieves the environment variable key. If it does not exist it returns the default.
//
GetEnv retrieves the environment variable key. If it does not exist it returns the default.
func
GetEnv
(
key
string
,
dfault
string
,
combineWith
...
string
)
string
{
value
:=
os
.
Getenv
(
key
)
if
value
==
""
{
...
...
internal/common/common_linux.go
浏览文件 @
5d0724f4
...
...
@@ -110,7 +110,7 @@ func Virtualization() (string, string, error) {
return
VirtualizationWithContext
(
context
.
Background
())
}
// required variables for concurrency safe virtualization caching
// required variables for concurrency safe virtualization caching
.
var
(
cachedVirtMap
map
[
string
]
string
cachedVirtMutex
sync
.
RWMutex
...
...
@@ -281,7 +281,7 @@ func GetOSRelease() (platform string, version string, err error) {
return
platform
,
version
,
nil
}
//
Remove quotes of the source string
//
trimQuotes removes quotes in the source string.
func
trimQuotes
(
s
string
)
string
{
if
len
(
s
)
>=
2
{
if
s
[
0
]
==
'"'
&&
s
[
len
(
s
)
-
1
]
==
'"'
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录