github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/apigw/v2/app_code/Create.go (about)

     1  package app_code
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type CreateOpts struct {
    10  	GatewayID string `json:"-"`
    11  	AppID     string `json:"-"`
    12  	AppCode   string `json:"app_code" required:"true"`
    13  }
    14  
    15  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*CodeResp, error) {
    16  	b, err := build.RequestBody(opts, "")
    17  	if err != nil {
    18  		return nil, err
    19  	}
    20  
    21  	raw, err := client.Post(client.ServiceURL("apigw", "instances", opts.GatewayID, "apps",
    22  		opts.AppID, "app-codes"), b, nil, &golangsdk.RequestOpts{
    23  		OkCodes: []int{201},
    24  	})
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  
    29  	var res CodeResp
    30  
    31  	err = extract.Into(raw.Body, &res)
    32  	return &res, err
    33  }
    34  
    35  type CodeResp struct {
    36  	ID         string `json:"id"`
    37  	AppID      string `json:"app_id"`
    38  	AppCode    string `json:"app_code"`
    39  	CreateTime string `json:"create_time"`
    40  }