github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/fgs/v2/aliases/requests.go (about)

     1  package aliases
     2  
     3  import "github.com/chnsz/golangsdk"
     4  
     5  // CreateOpts is a structure that used to create a alias for specified version.
     6  type CreateOpts struct {
     7  	// The URN of the function to which the alias and version are belong.
     8  	FunctionUrn string `json:"-" required:"true"`
     9  	// Function alias to be created.
    10  	Name string `json:"name" required:"true"`
    11  	// Version corresponding to the alias.
    12  	Version string `json:"version" required:"true"`
    13  	// Description of the alias.
    14  	Description string `json:"description,omitempty"`
    15  	// The weights configuration of the additional version.
    16  	AdditionalVersionWeights map[string]interface{} `json:"additional_version_weights,omitempty"`
    17  }
    18  
    19  var requestOpts = golangsdk.RequestOpts{
    20  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
    21  }
    22  
    23  // Create is a method to create a alias for specified version using given parameters.
    24  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Alias, error) {
    25  	b, err := golangsdk.BuildRequestBody(opts, "")
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	var r Alias
    31  	_, err = client.Post(rootURL(client, opts.FunctionUrn), b, &r, &golangsdk.RequestOpts{
    32  		MoreHeaders: requestOpts.MoreHeaders,
    33  	})
    34  	return &r, err
    35  }
    36  
    37  // Get is a method to obtain a specified alias using given parameters.
    38  func Get(client *golangsdk.ServiceClient, functionUrn, aliasName string) (*Alias, error) {
    39  	var r Alias
    40  	_, err := client.Get(resourceURL(client, functionUrn, aliasName), &r, &golangsdk.RequestOpts{
    41  		MoreHeaders: requestOpts.MoreHeaders,
    42  	})
    43  	return &r, err
    44  }
    45  
    46  // List is a method to obtain all aliases using given parameters.
    47  func List(client *golangsdk.ServiceClient, functionUrn string) ([]Alias, error) {
    48  	var r []Alias
    49  	_, err := client.Get(rootURL(client, functionUrn), &r, &golangsdk.RequestOpts{
    50  		MoreHeaders: requestOpts.MoreHeaders,
    51  	})
    52  	return r, err
    53  }
    54  
    55  // UpdateOpts is the structure used to update a specified alias.
    56  type UpdateOpts struct {
    57  	// The URN of the function to which the alias and version are belong.
    58  	FunctionUrn string `json:"-" required:"true"`
    59  	// The name of the alias.
    60  	Name string `json:"-" required:"true"`
    61  	// Version corresponding to the alias.
    62  	Version string `json:"version" required:"true"`
    63  	// Description of the alias.
    64  	Description string `json:"description,omitempty"`
    65  	// The weights configuration of the additional version.
    66  	AdditionalVersionWeights map[string]interface{} `json:"additional_version_weights,omitempty"`
    67  }
    68  
    69  // Update is a method to update a specified alias using given parameters.
    70  func Update(client *golangsdk.ServiceClient, opts UpdateOpts) (*Alias, error) {
    71  	b, err := golangsdk.BuildRequestBody(opts, "")
    72  	if err != nil {
    73  		return nil, err
    74  	}
    75  
    76  	var r Alias
    77  	_, err = client.Put(resourceURL(client, opts.FunctionUrn, opts.Name), b, &r, &golangsdk.RequestOpts{
    78  		MoreHeaders: requestOpts.MoreHeaders,
    79  	})
    80  	return &r, err
    81  }
    82  
    83  // Delete is a method to delete a specified alias.
    84  func Delete(client *golangsdk.ServiceClient, functionUrn, aliasName string) error {
    85  	_, err := client.Delete(resourceURL(client, functionUrn, aliasName), &golangsdk.RequestOpts{
    86  		MoreHeaders: requestOpts.MoreHeaders,
    87  	})
    88  	return err
    89  }