Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): Correct field order breaking requests #119

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ func (c *client) Logout(ctx context.Context) error {
// GetValue - port of python's get_value_by_xpath
// Retrieve raw value from router using XPath.
func (c *client) GetValue(ctx context.Context, xpath string) (*ValueResponse, error) {
ctx, span := tracer.Start(ctx, "SagemcomClient.GetValue")
ctx, span := tracer.Start(ctx, "SagemcomClient.GetValue", trace.WithAttributes(
attribute.String("xpath", xpath),
))
defer span.End()

actions := []action{
Expand Down
22 changes: 17 additions & 5 deletions client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,32 @@ import (
"time"
)

// requestBody - represents the body of a request to the API
//
// note: order of fields is significant - the API will reject requests if the
// order is not maintained
//
//nolint:govet
type requestBody struct {
AuthKey string `json:"auth-key"`
Actions []action `json:"actions"`
ID int `json:"id"`
SessionID int `json:"session-id"`
Cnonce int `json:"cnonce"`
Priority bool `json:"priority"`
Actions []action `json:"actions"`
Cnonce int `json:"cnonce"`
AuthKey string `json:"auth-key"`
}

// action - represents a single action to be performed
//
// note: order of fields is significant - the API will reject requests if the
// order is not maintained
//
//nolint:govet
type action struct {
Parameters map[string]any `json:"parameters,omitempty"`
ID int `json:"id"`
Method string `json:"method"`
Parameters map[string]any `json:"parameters,omitempty"`
XPath string `json:"xpath,omitempty"`
ID int `json:"id,omitempty"`
}

type sessionOptions struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ require (
go.opentelemetry.io/otel/sdk/log v0.9.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.33.0 // indirect
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ go.opentelemetry.io/proto/otlp v1.4.0 h1:TA9WRvW6zMwP+Ssb6fLoUIuirti1gGbP28GcKG1
go.opentelemetry.io/proto/otlp v1.4.0/go.mod h1:PPBWZIP98o2ElSqI35IHfu7hIhSwvc5N38Jw8pXuGFY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
Expand Down
Loading