Skip to content

Commit 2da9bbe

Browse files
committed
docs: improve and expand function documentation
- Improve documentation for `IsCommandAvailable` function - Enhance documentation for `ConvertToMap` function, including detailed description of arguments and return value - Add documentation for `Float32Ptr` function - Add documentation for `Int32Ptr` function Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 9218f84 commit 2da9bbe

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

util/util.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ import (
55
"strings"
66
)
77

8-
// IsCommandAvailable checks whether a command is available in the PATH.
8+
// IsCommandAvailable checks if a given command is available in the system's PATH.
9+
// It takes a string argument 'cmd' which represents the command to check.
10+
// It returns true if the command is found, otherwise false.
911
func IsCommandAvailable(cmd string) bool {
1012
_, err := exec.LookPath(cmd)
1113
return err == nil
1214
}
1315

14-
// ConvertToMap converts a slice of strings to a map.
16+
// ConvertToMap takes a slice of strings in the format "key=value" and converts it into a Data map.
17+
// Each string in the slice is split into a key and value pair using the first occurrence of the "=" character.
18+
// If a string does not contain the "=" character, it is ignored.
19+
// The resulting map contains the keys and values from the input slice.
20+
//
21+
// Args:
22+
// args ([]string): A slice of strings where each string is in the format "key=value".
23+
//
24+
// Returns:
25+
// Data: A map where the keys and values are derived from the input slice.
1526
func ConvertToMap(args []string) Data {
1627
m := make(Data)
1728
for _, arg := range args {
@@ -23,10 +34,14 @@ func ConvertToMap(args []string) Data {
2334
return m
2435
}
2536

37+
// Float32Ptr takes a float32 value and returns a pointer to that value.
38+
// This can be useful for passing float32 values to functions that require a pointer.
2639
func Float32Ptr(v float32) *float32 {
2740
return &v
2841
}
2942

43+
// Int32Ptr takes an int32 value and returns a pointer to that value.
44+
// This can be useful for passing int32 values to functions that require a pointer.
3045
func Int32Ptr(v int32) *int32 {
3146
return &v
3247
}

0 commit comments

Comments
 (0)