Skip to content

Commit e846bef

Browse files
committedOct 27, 2024·
♻️ refactor: update comment for all functions #2
1 parent c50f4d8 commit e846bef

File tree

6 files changed

+307
-398
lines changed

6 files changed

+307
-398
lines changed
 

‎json.go

+35-28
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ var _json = jsonI.ConfigCompatibleWithStandardLibrary
1313
// during marshalling, it returns the error.
1414
//
1515
// Parameters:
16-
// - `v`: The Go value to be marshalled into JSON.
16+
// - `v`: The Go value to be marshalled into JSON.
1717
//
1818
// Returns:
19-
// - A byte slice containing the JSON representation of the input value.
20-
// - An error if the marshalling fails.
19+
// - A byte slice containing the JSON representation of the input value.
20+
// - An error if the marshalling fails.
2121
//
2222
// Example:
23-
// jsonData, err := Marshal(myStruct)
23+
//
24+
// jsonData, err := Marshal(myStruct)
2425
func Marshal(v interface{}) ([]byte, error) {
2526
return _json.Marshal(v)
2627
}
@@ -32,16 +33,17 @@ func Marshal(v interface{}) ([]byte, error) {
3233
// It returns the resulting JSON byte slice or an error if marshalling fails.
3334
//
3435
// Parameters:
35-
// - `v`: The Go value to be marshalled into JSON.
36-
// - `prefix`: A string that will be prefixed to each line of the output JSON.
37-
// - `indent`: A string used for indentation (typically a series of spaces or a tab).
36+
// - `v`: The Go value to be marshalled into JSON.
37+
// - `prefix`: A string that will be prefixed to each line of the output JSON.
38+
// - `indent`: A string used for indentation (typically a series of spaces or a tab).
3839
//
3940
// Returns:
40-
// - A byte slice containing the formatted JSON representation of the input value.
41-
// - An error if the marshalling fails.
41+
// - A byte slice containing the formatted JSON representation of the input value.
42+
// - An error if the marshalling fails.
4243
//
4344
// Example:
44-
// jsonIndented, err := MarshalIndent(myStruct, "", " ")
45+
//
46+
// jsonIndented, err := MarshalIndent(myStruct, "", " ")
4547
func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
4648
return _json.MarshalIndent(v, prefix, indent)
4749
}
@@ -53,14 +55,15 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
5355
// JSON string. If an error occurs during the process, it returns an error.
5456
//
5557
// Parameters:
56-
// - `v`: The Go value to be marshalled into JSON.
58+
// - `v`: The Go value to be marshalled into JSON.
5759
//
5860
// Returns:
59-
// - A string containing the JSON representation of the input value.
60-
// - An error if the marshalling fails.
61+
// - A string containing the JSON representation of the input value.
62+
// - An error if the marshalling fails.
6163
//
6264
// Example:
63-
// jsonString, err := MarshalToString(myStruct)
65+
//
66+
// jsonString, err := MarshalToString(myStruct)
6467
func MarshalToString(v interface{}) (string, error) {
6568
return _json.MarshalToString(v)
6669
}
@@ -72,14 +75,15 @@ func MarshalToString(v interface{}) (string, error) {
7275
// is successful, it populates the value `v`. If an error occurs, it returns the error.
7376
//
7477
// Parameters:
75-
// - `data`: A byte slice containing JSON data to be unmarshalled.
76-
// - `v`: A pointer to the Go value where the unmarshalled data will be stored.
78+
// - `data`: A byte slice containing JSON data to be unmarshalled.
79+
// - `v`: A pointer to the Go value where the unmarshalled data will be stored.
7780
//
7881
// Returns:
79-
// - An error if the unmarshalling fails.
82+
// - An error if the unmarshalling fails.
8083
//
8184
// Example:
82-
// err := Unmarshal(jsonData, &myStruct)
85+
//
86+
// err := Unmarshal(jsonData, &myStruct)
8387
func Unmarshal(data []byte, v interface{}) error {
8488
return _json.Unmarshal(data, v)
8589
}
@@ -91,14 +95,15 @@ func Unmarshal(data []byte, v interface{}) error {
9195
// successful, it populates the value `v`. If an error occurs, it returns the error.
9296
//
9397
// Parameters:
94-
// - `str`: A string containing JSON data to be unmarshalled.
95-
// - `v`: A pointer to the Go value where the unmarshalled data will be stored.
98+
// - `str`: A string containing JSON data to be unmarshalled.
99+
// - `v`: A pointer to the Go value where the unmarshalled data will be stored.
96100
//
97101
// Returns:
98-
// - An error if the unmarshalling fails.
102+
// - An error if the unmarshalling fails.
99103
//
100104
// Example:
101-
// err := UnmarshalFromString(jsonString, &myStruct)
105+
//
106+
// err := UnmarshalFromString(jsonString, &myStruct)
102107
func UnmarshalFromString(str string, v interface{}) error {
103108
return _json.UnmarshalFromString(str, v)
104109
}
@@ -110,13 +115,14 @@ func UnmarshalFromString(str string, v interface{}) error {
110115
// MarshalToString function. If an error occurs during marshalling, it returns an empty string.
111116
//
112117
// Parameters:
113-
// - `data`: The Go value to be converted to JSON, or a string to be returned directly.
118+
// - `data`: The Go value to be converted to JSON, or a string to be returned directly.
114119
//
115120
// Returns:
116-
// - A string containing the JSON representation of the input value, or an empty string if an error occurs.
121+
// - A string containing the JSON representation of the input value, or an empty string if an error occurs.
117122
//
118123
// Example:
119-
// jsonStr := Json(myStruct)
124+
//
125+
// jsonStr := Json(myStruct)
120126
func Json(data interface{}) string {
121127
s, ok := data.(string)
122128
if ok {
@@ -136,13 +142,14 @@ func Json(data interface{}) string {
136142
// the MarshalIndent function. If an error occurs during marshalling, it returns an empty string.
137143
//
138144
// Parameters:
139-
// - `data`: The Go value to be converted to pretty-printed JSON, or a string to be returned directly.
145+
// - `data`: The Go value to be converted to pretty-printed JSON, or a string to be returned directly.
140146
//
141147
// Returns:
142-
// - A string containing the pretty-printed JSON representation of the input value, or an empty string if an error occurs.
148+
// - A string containing the pretty-printed JSON representation of the input value, or an empty string if an error occurs.
143149
//
144150
// Example:
145-
// jsonPrettyStr := JsonPretty(myStruct)
151+
//
152+
// jsonPrettyStr := JsonPretty(myStruct)
146153
func JsonPretty(data interface{}) string {
147154
s, ok := data.(string)
148155
if ok {

‎normalization.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ package unify4g
66
// more common ASCII equivalents. The specific transformations are defined in a switch statement that
77
// maps each rune to its normalized string value. This includes:
88
//
9-
// - Ligatures (e.g., 'Æ' to "AE", 'Œ' to "OE")
10-
// - Special characters (e.g., 'ß' to "ss")
11-
// - Accented characters (e.g., 'é' to "e", 'ç' to "c")
12-
// - Various other characters with diacritics are converted to their closest ASCII equivalent.
9+
// - Ligatures (e.g., 'Æ' to "AE", 'Œ' to "OE")
10+
// - Special characters (e.g., 'ß' to "ss")
11+
// - Accented characters (e.g., 'é' to "e", 'ç' to "c")
12+
// - Various other characters with diacritics are converted to their closest ASCII equivalent.
1313
//
1414
// If the input rune does not match any of the defined cases, the function returns the rune as a string,
1515
// preserving its original representation.
1616
//
1717
// Parameters:
18-
// - `r`: A rune representing a Unicode character that may need normalization.
18+
// - `r`: A rune representing a Unicode character that may need normalization.
1919
//
2020
// Returns:
2121
// - A string that represents the normalized form of the input rune. This string is typically ASCII,
2222
// making it easier to handle in contexts where only basic characters are expected.
2323
//
2424
// Example:
2525
//
26-
// normalized := normalize_rune('É')
27-
// fmt.Println(normalized) // Output: "E"
26+
// normalized := normalize_rune('É')
27+
// fmt.Println(normalized) // Output: "E"
2828
//
2929
// Notes:
3030
// - This function is particularly useful for text processing, sanitization, or when preparing data
3131
// for systems that require ASCII-compatible strings.
3232
//
3333
// Replacements are taken from
34-
// - https://github.com/sindresorhus/slugify/blob/master/replacements.js
35-
// - https://github.com/cocur/slugify/tree/master/Resources/rules
34+
// - https://github.com/sindresorhus/slugify/blob/master/replacements.js
35+
// - https://github.com/cocur/slugify/tree/master/Resources/rules
3636
func normalize_rune(r rune) string {
3737
switch r {
3838
case 'Ə':

‎random.go

+13-14
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ func init() {
2424
// r.Intn(max-min+1) + min, where `r` is a custom random generator that has been initialized elsewhere in the code.
2525
//
2626
// Parameters:
27-
// - `min`: The lower bound of the random number range (inclusive).
28-
// - `max`: The upper bound of the random number range (inclusive).
27+
// - `min`: The lower bound of the random number range (inclusive).
28+
// - `max`: The upper bound of the random number range (inclusive).
2929
//
3030
// Returns:
31-
// - A random integer between `min` and `max`, including both bounds.
31+
// - A random integer between `min` and `max`, including both bounds.
3232
//
3333
// Example:
3434
//
35-
// randomNum := NextInt(1, 10)
36-
// fmt.Println("Random number between 1 and 10:", randomNum)
35+
// randomNum := NextInt(1, 10)
36+
// fmt.Println("Random number between 1 and 10:", randomNum)
3737
func NextInt(min, max int) int {
3838
if min >= max {
3939
return min // or handle the error appropriately
@@ -57,21 +57,20 @@ func NextInt(min, max int) int {
5757
// in the result by using the formula: r.Intn(max-min+1) + min.
5858
//
5959
// Parameters:
60-
// - `min`: The lower bound of the random number range (inclusive).
61-
// - `max`: The upper bound of the random number range (inclusive).
60+
// - `min`: The lower bound of the random number range (inclusive).
61+
// - `max`: The upper bound of the random number range (inclusive).
6262
//
6363
// Returns:
64-
// - A random integer between `min` and `max`, including both bounds.
64+
// - A random integer between `min` and `max`, including both bounds.
6565
//
6666
// Example:
6767
//
68-
// randomNum := NextReseed(1, 10)
69-
// fmt.Println("Random number between 1 and 10 after reseeding:", randomNum)
68+
// randomNum := NextReseed(1, 10)
69+
// fmt.Println("Random number between 1 and 10 after reseeding:", randomNum)
7070
func NextReseed(min, max int) int {
7171
// Reseed the custom random generator with a new seed
7272
x := time.Now().UTC().UnixNano() + int64(r.Int())
7373
r.Seed(x)
74-
7574
// Ensure max is included in the range
7675
if min >= max {
7776
return min
@@ -88,12 +87,12 @@ func NextReseed(min, max int) int {
8887
// It abstracts away the error handling by returning an empty string in case of failure.
8988
//
9089
// Returns:
91-
// - A string representing the newly generated UUID.
92-
// - An empty string if an error occurs during UUID generation.
90+
// - A string representing the newly generated UUID.
91+
// - An empty string if an error occurs during UUID generation.
9392
//
9493
// Example:
9594
//
96-
// uuid := NextUUID()
95+
// uuid := NextUUID()
9796
//
9897
// if uuid == "" {
9998
// fmt.Println("Failed to generate UUID")

‎reflect.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,29 @@ import "reflect"
55
// IsPrimitive checks whether the given value is a primitive type in Go.
66
//
77
// Primitive types include:
8-
// - Signed integers: int, int8, int16, int32, int64
9-
// - Unsigned integers: uint, uint8, uint16, uint32, uint64, uintptr
10-
// - Floating-point numbers: float32, float64
11-
// - Complex numbers: complex64, complex128
12-
// - Boolean: bool
13-
// - String: string
8+
// - Signed integers: int, int8, int16, int32, int64
9+
// - Unsigned integers: uint, uint8, uint16, uint32, uint64, uintptr
10+
// - Floating-point numbers: float32, float64
11+
// - Complex numbers: complex64, complex128
12+
// - Boolean: bool
13+
// - String: string
1414
//
1515
// The function first checks if the input value is `nil`, returning `false` if so. Otherwise, it uses reflection to determine
1616
// the type of the value and compares it against known primitive types.
1717
//
1818
// Parameters:
19-
// - `value`: An interface{} that can hold any Go value. The function checks the type of this value.
19+
// - `value`: An interface{} that can hold any Go value. The function checks the type of this value.
2020
//
2121
// Returns:
22-
// - `true` if the value is of a primitive type.
23-
// - `false` if the value is `nil` or not a primitive type.
22+
// - `true` if the value is of a primitive type.
23+
// - `false` if the value is `nil` or not a primitive type.
2424
//
2525
// Example:
2626
//
27-
// primitive := 42
28-
//
27+
// primitive := 42
2928
// if IsPrimitive(primitive) {
3029
// fmt.Println("The value is a primitive type.")
3130
// } else {
32-
//
3331
// fmt.Println("The value is not a primitive type.")
3432
// }
3533
func IsPrimitive(value interface{}) bool {

‎strings.go

+233-326
Large diffs are not rendered by default.

‎uuid.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,16 @@ import (
1515
// XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, where X is a hexadecimal digit.
1616
//
1717
// Returns:
18-
// - A string representing the newly generated UUID.
19-
// - An error if there is an issue opening or reading from /dev/urandom.
18+
// - A string representing the newly generated UUID.
19+
// - An error if there is an issue opening or reading from /dev/urandom.
2020
//
2121
// Example:
2222
//
23-
// uuid, err := GenerateUUID()
24-
//
25-
// if err != nil {
26-
// log.Fatalf("Failed to generate UUID: %v", err)
27-
// }
28-
//
29-
// fmt.Println("Generated UUID:", uuid)
23+
// uuid, err := GenerateUUID()
24+
// if err != nil {
25+
// log.Fatalf("Failed to generate UUID: %v", err)
26+
// }
27+
// fmt.Println("Generated UUID:", uuid)
3028
//
3129
// Notes:
3230
// - This function is designed for Unix-based systems. On non-Unix systems, this may not work because /dev/urandom

0 commit comments

Comments
 (0)
Please sign in to comment.