-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(products): Improve API usability. (#572)
* Add 'EnableOutput' type aliases in each product, so that users of the API don't need to know whether that product has its own EnableOutput or not. Add 'NewEnableOutput' function so that users of the API can easily construct mock output instances. * Add 'ProductName' constant in each product, so that users of the API will have access to the canonical name of the product along with its product_id. * Change package names to conform to Go guidelines (remove underscores). * Change APIs to accept and return by-value instead of by-pointer, as using by-pointer structures can be difficult in generic parameter contexts and the structures involved are small (so there is no real benefit to avoiding by-value passing).
- Loading branch information
Showing
118 changed files
with
733 additions
and
570 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package botmanagement | ||
|
||
import ( | ||
"github.com/fastly/go-fastly/v9/fastly" | ||
"github.com/fastly/go-fastly/v9/fastly/products" | ||
"github.com/fastly/go-fastly/v9/internal/productcore" | ||
) | ||
|
||
const ( | ||
ProductID = "bot_management" | ||
ProductName = "Bot Management" | ||
) | ||
|
||
// EnableOutput holds the details returned by the API from 'Get' and | ||
// 'Enable' operations; this alias exists to ensure that users of this | ||
// package will have a stable name to reference. | ||
type EnableOutput = products.EnableOutput | ||
|
||
// Get gets the status of the Bot Management product on the service. | ||
func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { | ||
return productcore.Get[EnableOutput](&productcore.GetInput{ | ||
Client: c, | ||
ProductID: ProductID, | ||
ServiceID: serviceID, | ||
}) | ||
} | ||
|
||
// Enable enables the Bot Management product on the service. | ||
func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { | ||
return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ | ||
Client: c, | ||
ProductID: ProductID, | ||
ServiceID: serviceID, | ||
}) | ||
} | ||
|
||
// Disable disables the Bot Management product on the service. | ||
func Disable(c *fastly.Client, serviceID string) error { | ||
return productcore.Delete(&productcore.DeleteInput{ | ||
Client: c, | ||
ProductID: ProductID, | ||
ServiceID: serviceID, | ||
}) | ||
} | ||
|
||
// NewEnableOutput is used to construct mock API output structures for | ||
// use in tests. | ||
func NewEnableOutput(serviceID string) EnableOutput { | ||
return products.NewEnableOutput(ProductID, serviceID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Package botmanagement contains API operations to enable and | ||
// disable the Bot Management product on a service | ||
package botmanagement |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package brotlicompression | ||
|
||
import ( | ||
"github.com/fastly/go-fastly/v9/fastly" | ||
"github.com/fastly/go-fastly/v9/fastly/products" | ||
"github.com/fastly/go-fastly/v9/internal/productcore" | ||
) | ||
|
||
const ( | ||
ProductID = "brotli_compression" | ||
ProductName = "Brotli Compression" | ||
) | ||
|
||
// EnableOutput holds the details returned by the API from 'Get' and | ||
// 'Enable' operations; this alias exists to ensure that users of this | ||
// package will have a stable name to reference. | ||
type EnableOutput = products.EnableOutput | ||
|
||
// Get gets the status of the Brotli Compression product on the service. | ||
func Get(c *fastly.Client, serviceID string) (EnableOutput, error) { | ||
return productcore.Get[EnableOutput](&productcore.GetInput{ | ||
Client: c, | ||
ProductID: ProductID, | ||
ServiceID: serviceID, | ||
}) | ||
} | ||
|
||
// Enable enables the Brotli Compression product on the service. | ||
func Enable(c *fastly.Client, serviceID string) (EnableOutput, error) { | ||
return productcore.Put[EnableOutput](&productcore.PutInput[products.NullInput]{ | ||
Client: c, | ||
ProductID: ProductID, | ||
ServiceID: serviceID, | ||
}) | ||
} | ||
|
||
// Disable disables the Brotli Compression product on the service. | ||
func Disable(c *fastly.Client, serviceID string) error { | ||
return productcore.Delete(&productcore.DeleteInput{ | ||
Client: c, | ||
ProductID: ProductID, | ||
ServiceID: serviceID, | ||
}) | ||
} | ||
|
||
// NewEnableOutput is used to construct mock API output structures for | ||
// use in tests. | ||
func NewEnableOutput(serviceID string) EnableOutput { | ||
return products.NewEnableOutput(ProductID, serviceID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Package brotlicompression contains API operations to enable and | ||
// disable the Brotli Compression product on a service | ||
package brotlicompression |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.