Files
threshold/api/targets/option.gen.go
T
Todd Knight 5553fd989f Host Set and Target SDK Generation using new Pathing (#320)
* Adding new style template starts.

* Host-set crud changes generated and tested.

* Add templates for every resource with the new pathing.  Only host-sets has testing or the backed pathing.

* Only generate new style API if requested in the input.  Have disabling old be opt in.
2020-09-02 12:31:30 -07:00

93 lines
2.3 KiB
Go

package targets
import (
"github.com/hashicorp/boundary/api"
)
// Option is a func that sets optional attributes for a call. This does not need
// to be used directly, but instead option arguments are built from the
// functions in this package. WithX options set a value to that given in the
// argument; DefaultX options indicate that the value should be set to its
// default. When an API call is made options are processed in ther order they
// appear in the function call, so for a given argument X, a succession of WithX
// or DefaultX calls will result in the last call taking effect.
type Option func(*options)
type options struct {
postMap map[string]interface{}
queryMap map[string]string
withScopeId string
withAutomaticVersioning bool
}
func getDefaultOptions() options {
return options{
postMap: make(map[string]interface{}),
queryMap: make(map[string]string),
}
}
func getOpts(opt ...Option) (options, []api.Option) {
opts := getDefaultOptions()
for _, o := range opt {
o(&opts)
}
var apiOpts []api.Option
if opts.withScopeId != "" {
apiOpts = append(apiOpts, api.WithScopeId(opts.withScopeId))
}
return opts, apiOpts
}
func WithScopeId(id string) Option {
return func(o *options) {
o.withScopeId = id
}
}
// If set, and if the version is zero during an update, the API will perform a
// fetch to get the current version of the resource and populate it during the
// update call. This is convenient but opens up the possibility for subtle
// order-of-modification issues, so use carefully.
func WithAutomaticVersioning() Option {
return func(o *options) {
o.withAutomaticVersioning = true
}
}
func WithDefaultPort(inDefaultPort uint32) Option {
return func(o *options) {
o.postMap["default_port"] = inDefaultPort
}
}
func DefaultDefaultPort() Option {
return func(o *options) {
o.postMap["default_port"] = nil
}
}
func WithDescription(inDescription string) Option {
return func(o *options) {
o.postMap["description"] = inDescription
}
}
func DefaultDescription() Option {
return func(o *options) {
o.postMap["description"] = nil
}
}
func WithName(inName string) Option {
return func(o *options) {
o.postMap["name"] = inName
}
}
func DefaultName() Option {
return func(o *options) {
o.postMap["name"] = nil
}
}