Skip to content

Commit fbdd224

Browse files
committed
SDK regeneration
1 parent 38ec74d commit fbdd224

File tree

13 files changed

+1346
-58
lines changed

13 files changed

+1346
-58
lines changed

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# Lattice SDK Go library
1+
# Anduril Go Library
22

33
![](https://www.anduril.com/lattice-sdk/)
44

5-
The Lattice SDK Go library provides convenient access to the Lattice API from Go.
5+
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fanduril%2Flattice-sdk-go)
6+
7+
The Anduril Go library provides convenient access to the Anduril APIs from Go.
68

79
## Documentation
810

@@ -37,7 +39,7 @@ import (
3739
client "github.com/anduril/lattice-sdk-go/v2/client"
3840
option "github.com/anduril/lattice-sdk-go/v2/option"
3941
context "context"
40-
Lattice "github.com/anduril/lattice-sdk-go/v2"
42+
v2 "github.com/anduril/lattice-sdk-go/v2"
4143
)
4244

4345
func do() {
@@ -48,7 +50,7 @@ func do() {
4850
)
4951
client.Entities.LongPollEntityEvents(
5052
context.TODO(),
51-
&Lattice.EntityEventRequest{
53+
&v2.EntityEventRequest{
5254
SessionToken: "sessionToken",
5355
},
5456
)
@@ -162,3 +164,17 @@ defer cancel()
162164

163165
response, err := client.Entities.LongPollEntityEvents(ctx, ...)
164166
```
167+
168+
## Reference
169+
170+
A full reference for this library is available [here](https://github.com/anduril/lattice-sdk-go/blob/HEAD/./reference.md).
171+
172+
## Contributing
173+
174+
While we value open-source contributions to this SDK, this library is generated programmatically.
175+
Additions made directly to this library would have to be moved over to our generation code,
176+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
177+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
178+
an issue first to discuss with us!
179+
180+
On the other hand, contributions to the README are always very welcome!

client/client.go

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/client_test.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/request_option.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entities/client.go

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entities/raw_client.go

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/query.go

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,81 @@ type QueryEncoder interface {
2424
EncodeQueryValues(key string, v *url.Values) error
2525
}
2626

27-
// QueryValues encodes url.Values from request objects.
28-
//
29-
// Note: This type is inspired by Google's query encoding library, but
30-
// supports far less customization and is tailored to fit this SDK's use case.
31-
//
32-
// Ref: https://github.com/google/go-querystring
33-
func QueryValues(v interface{}) (url.Values, error) {
27+
// prepareValue handles common validation and unwrapping logic for both functions
28+
func prepareValue(v interface{}) (reflect.Value, url.Values, error) {
3429
values := make(url.Values)
3530
val := reflect.ValueOf(v)
3631
for val.Kind() == reflect.Ptr {
3732
if val.IsNil() {
38-
return values, nil
33+
return reflect.Value{}, values, nil
3934
}
4035
val = val.Elem()
4136
}
4237

4338
if v == nil {
44-
return values, nil
39+
return reflect.Value{}, values, nil
4540
}
4641

4742
if val.Kind() != reflect.Struct {
48-
return nil, fmt.Errorf("query: Values() expects struct input. Got %v", val.Kind())
43+
return reflect.Value{}, nil, fmt.Errorf("query: Values() expects struct input. Got %v", val.Kind())
4944
}
5045

5146
err := reflectValue(values, val, "")
47+
if err != nil {
48+
return reflect.Value{}, nil, err
49+
}
50+
51+
return val, values, nil
52+
}
53+
54+
// QueryValues encodes url.Values from request objects.
55+
//
56+
// Note: This type is inspired by Google's query encoding library, but
57+
// supports far less customization and is tailored to fit this SDK's use case.
58+
//
59+
// Ref: https://github.com/google/go-querystring
60+
func QueryValues(v interface{}) (url.Values, error) {
61+
_, values, err := prepareValue(v)
62+
return values, err
63+
}
64+
65+
// QueryValuesWithDefaults encodes url.Values from request objects
66+
// and default values, merging the defaults into the request.
67+
// It's expected that the values of defaults are wire names.
68+
func QueryValuesWithDefaults(v interface{}, defaults map[string]interface{}) (url.Values, error) {
69+
val, values, err := prepareValue(v)
70+
if err != nil {
71+
return values, err
72+
}
73+
74+
// apply defaults to zero-value fields directly on the original struct
75+
valType := val.Type()
76+
for i := 0; i < val.NumField(); i++ {
77+
field := val.Field(i)
78+
fieldType := valType.Field(i)
79+
fieldName := fieldType.Name
80+
81+
if fieldType.PkgPath != "" && !fieldType.Anonymous {
82+
// Skip unexported fields.
83+
continue
84+
}
85+
86+
// check if field is zero value and we have a default for it
87+
if field.CanSet() && field.IsZero() {
88+
tag := fieldType.Tag.Get("url")
89+
if tag == "" || tag == "-" {
90+
continue
91+
}
92+
wireName, _ := parseTag(tag)
93+
if wireName == "" {
94+
wireName = fieldName
95+
}
96+
if defaultVal, exists := defaults[wireName]; exists {
97+
values.Set(wireName, valueString(reflect.ValueOf(defaultVal), tagOptions{}, reflect.StructField{}))
98+
}
99+
}
100+
}
101+
52102
return values, err
53103
}
54104

0 commit comments

Comments
 (0)