-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from dubbogo/feature/runtime
Add: get host/container cpu/mem info
- Loading branch information
Showing
10 changed files
with
209 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package gxfilepath | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// Exists returns whether the given file or directory exists | ||
func Exists(path string) (bool, error) { | ||
_, err := os.Lstat(path) | ||
if err == nil { | ||
return true, nil | ||
} | ||
if os.IsNotExist(err) { | ||
return false, nil | ||
} | ||
|
||
return false, err | ||
} | ||
|
||
// FileExists checks whether a file exists in the given path. It also fails if | ||
// the path points to a directory or there is an error when trying to check the file. | ||
func FileExists(path string) (bool, error) { | ||
info, err := os.Lstat(path) | ||
if err != nil { | ||
return false, err | ||
} | ||
if info.IsDir() { | ||
return false, fmt.Errorf("%q is a directory", path) | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
// DirExists checks whether a directory exists in the given path. It also fails | ||
// if the path is a file rather a directory or there is an error checking whether it exists. | ||
func DirExists(path string) (bool, error) { | ||
info, err := os.Lstat(path) | ||
if err != nil { | ||
return false, err | ||
} | ||
if !info.IsDir() { | ||
return false, fmt.Errorf("%q is a file", path) | ||
} | ||
|
||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package gxfilepath | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFileExists(t *testing.T) { | ||
file := "./path_test.go" | ||
ok, err := Exists(file) | ||
assert.True(t, ok) | ||
assert.Nil(t, err) | ||
ok, err = DirExists(file) | ||
assert.False(t, ok) | ||
assert.NotNil(t, err) | ||
ok, err = FileExists(file) | ||
assert.True(t, ok) | ||
assert.Nil(t, err) | ||
|
||
file = "./path_test1.go" | ||
ok, err = Exists(file) | ||
assert.False(t, ok) | ||
assert.Nil(t, err) | ||
ok, err = DirExists(file) | ||
assert.False(t, ok) | ||
assert.NotNil(t, err) | ||
ok, err = FileExists(file) | ||
assert.False(t, ok) | ||
assert.NotNil(t, err) | ||
} | ||
|
||
func TestDirExists(t *testing.T) { | ||
file := "./" | ||
ok, err := Exists(file) | ||
assert.True(t, ok) | ||
assert.Nil(t, err) | ||
ok, err = DirExists(file) | ||
assert.True(t, ok) | ||
assert.Nil(t, err) | ||
ok, err = FileExists(file) | ||
assert.False(t, ok) | ||
assert.NotNil(t, err) | ||
|
||
file = "./go" | ||
ok, err = Exists(file) | ||
assert.False(t, ok) | ||
assert.Nil(t, err) | ||
ok, err = DirExists(file) | ||
assert.False(t, ok) | ||
assert.NotNil(t, err) | ||
ok, err = FileExists(file) | ||
assert.False(t, ok) | ||
assert.NotNil(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters