Skip to content

Commit 1dcf5cd

Browse files
[SERV-1275] Add example to godocs (#178)
Co-authored-by: Kevin S. Clarke <[email protected]>
1 parent 52be3e4 commit 1dcf5cd

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package util
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
)
7+
8+
func ExampleProfiles() {
9+
profiles := NewProfiles()
10+
11+
profile, err := NewProfile("example", []string{"Validation1", "Validation2"})
12+
if err != nil {
13+
panic(err)
14+
}
15+
16+
if err := profiles.SetProfile(profile); err != nil {
17+
panic(err)
18+
}
19+
20+
// Print the profile name
21+
fmt.Println(profiles.GetProfile("example").GetName())
22+
23+
// Print the snapshot JSON
24+
snapshot := profiles.Snapshot()
25+
jsonData, err := json.Marshal(snapshot)
26+
if err != nil {
27+
panic(err)
28+
}
29+
fmt.Println(string(jsonData))
30+
}

validation/util/profiles.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
package util
22

3-
// This file contains utilities for creating and working with validation profiles.
4-
//
5-
// Example usage:
6-
//
7-
// profiles := NewProfiles()
8-
// if profile, err := NewProfile("example", []string{"Validation1", "Validation2"}); err != nil {
9-
// require.NoError(t, err)
10-
// } else {
11-
// err = profiles.SetProfile(profile)
12-
// require.NoError(t, err)
13-
//
14-
// fmt.Println(profiles.GetProfile("example").GetName())
15-
// }
16-
//
17-
// snapshot := profiles.Snapshot()
18-
// if jsonData, err := json.Marshal(snapshot); err != nil {
19-
// require.NoError(t, err)
20-
// } else {
21-
// fmt.Println(string(jsonData))
22-
// }
233
import (
244
"encoding/json"
255
"fmt"

0 commit comments

Comments
 (0)