-
Notifications
You must be signed in to change notification settings - Fork 4
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 #30 from t4lz/go-statfs
Add test image for go-statfs E2E test
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM golang:1.23-alpine3.20 | ||
WORKDIR /app | ||
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change | ||
COPY go.mod test.txt ./ | ||
RUN go mod download && go mod verify | ||
|
||
COPY . . | ||
RUN go build -v -o /app/go-statfs ./... | ||
|
||
CMD ["/app/go-statfs"] |
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,3 @@ | ||
module go-statfs | ||
|
||
go 1.23.5 |
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,54 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
_ "net" // for dynamic linking | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func main() { | ||
rootPath := "/" | ||
var statfs syscall.Statfs_t | ||
err := syscall.Statfs(rootPath, &statfs) | ||
if err != nil { | ||
fmt.Println("Error:", err) | ||
return | ||
} | ||
|
||
// Convert struct to a JSON-friendly format | ||
data := map[string]interface{}{ | ||
"bavail": statfs.Bavail, | ||
"bfree": statfs.Bfree, | ||
"blocks": statfs.Blocks, | ||
"bsize": statfs.Bsize, | ||
"ffree": statfs.Ffree, | ||
"files": statfs.Files, | ||
"flags": statfs.Flags, | ||
"frsize": statfs.Frsize, | ||
"fsid": []int32{int32(statfs.Fsid.X__val[0]), int32(statfs.Fsid.X__val[1])}, | ||
"namelen": statfs.Namelen, | ||
"spare": statfs.Spare, | ||
"type": statfs.Type, | ||
} | ||
|
||
// Convert to JSON | ||
jsonData, err := json.MarshalIndent(data, "", " ") | ||
if err != nil { | ||
fmt.Println("JSON Encoding Error:", err) | ||
return | ||
} | ||
|
||
// Print JSON | ||
fmt.Println(string(jsonData)) | ||
|
||
// Create a channel to receive OS signals | ||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
// Block forever waiting for a signal | ||
<-sigs | ||
|
||
} |
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 @@ | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |