Skip to content

Commit ba239a1

Browse files
Use existing function for nil string setting
In the previous PR (#138) I added a `NilString` function and used it to return `nil` if a string was empty, or a pointer to the string otherwise, but this functionality is already available via the `readStringPtrFromResource` function, so use that instead.
1 parent f3e7282 commit ba239a1

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

kong/resource_kong_consumer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func resourceKongConsumer() *schema.Resource {
4343
func resourceKongConsumerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
4444

4545
consumerRequest := &kong.Consumer{
46-
Username: NilString(d.Get("username").(string)),
47-
CustomID: NilString(d.Get("custom_id").(string)),
46+
Username: readStringPtrFromResource(d, "username"),
47+
CustomID: readStringPtrFromResource(d, "custom_id"),
4848
Tags: readStringArrayPtrFromResource(d, "tags"),
4949
}
5050

kong/utils.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,3 @@ func IDToString(v *string) string {
154154
}
155155
return *v
156156
}
157-
158-
// NilString converts a string to a string pointer,
159-
// or if empty returns nil.
160-
func NilString(str string) *string {
161-
if str == "" {
162-
return nil
163-
} else {
164-
return kong.String(str)
165-
}
166-
}

0 commit comments

Comments
 (0)