Skip to content

Commit

Permalink
Allow any type to be used with request set
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Apr 10, 2023
1 parent 1b6bcef commit f1cf624
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.9 (unreleased)

- Allow any type to be used with `Body.Set()`

## 0.1.8

- Add option to skip discovery
Expand Down
17 changes: 11 additions & 6 deletions req.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,23 @@ type YangPatchEditModel struct {

// Body wraps SJSON for building JSON body strings.
// Usage example:
// Body{}.Set(Cisco-IOS-XE-native:native.hostname", "ROUTER-1").Str
//
// Body{}.Set(Cisco-IOS-XE-native:native.hostname", "ROUTER-1").Str
type Body struct {
Str string
}

// Set sets a JSON path to a value.
func (body Body) Set(path, value string) Body {
func (body Body) Set(path string, value interface{}) Body {
res, _ := sjson.Set(body.Str, path, value)
body.Str = res
return body
}

// SetRaw sets a JSON path to a raw string value.
// This is primarily used for building up nested structures, e.g.:
// Body{}.SetRaw("Cisco-IOS-XE-native:native", Body{}.Set("hostname", "ROUTER-1").Str).Str
//
// Body{}.SetRaw("Cisco-IOS-XE-native:native", Body{}.Set("hostname", "ROUTER-1").Str).Str
func (body Body) SetRaw(path, rawValue string) Body {
res, _ := sjson.SetRaw(body.Str, path, rawValue)
body.Str = res
Expand All @@ -62,11 +64,14 @@ type Req struct {
}

// Query sets an HTTP query parameter.
//
// client.GetData("Cisco-IOS-XE-native:native", restconf.Query("content", "config"))
//
// Or set multiple parameters:
// client.GetData("Cisco-IOS-XE-native:native",
// restconf.Query("content", "config"),
// restconf.Query("depth", "1"))
//
// client.GetData("Cisco-IOS-XE-native:native",
// restconf.Query("content", "config"),
// restconf.Query("depth", "1"))
func Query(k, v string) func(req *Req) {
return func(req *Req) {
q := req.HttpReq.URL.Query()
Expand Down

0 comments on commit f1cf624

Please sign in to comment.