github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/loadbalancer/apply_request.go (about)

     1  // Copyright 2016-2022 The Libsacloud Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package loadbalancer
    16  
    17  import (
    18  	"github.com/sacloud/libsacloud/v2/helper/service"
    19  	"github.com/sacloud/libsacloud/v2/helper/validate"
    20  	"github.com/sacloud/libsacloud/v2/sacloud"
    21  	"github.com/sacloud/libsacloud/v2/sacloud/types"
    22  )
    23  
    24  type ApplyRequest struct {
    25  	ID   types.ID // for update
    26  	Zone string   `validate:"required"`
    27  
    28  	Name               string `validate:"required"`
    29  	Description        string `validate:"min=0,max=512"`
    30  	Tags               types.Tags
    31  	IconID             types.ID
    32  	SwitchID           types.ID `validate:"required"`
    33  	PlanID             types.ID `validate:"required"`
    34  	VRID               int
    35  	IPAddresses        []string `validate:"required,min=1,max=2,dive,ipv4"`
    36  	NetworkMaskLen     int      `validate:"required"`
    37  	DefaultRoute       string   `validate:"omitempty,ipv4"`
    38  	VirtualIPAddresses sacloud.LoadBalancerVirtualIPAddresses
    39  
    40  	SettingsHash string // for update
    41  	NoWait       bool
    42  }
    43  
    44  func (req *ApplyRequest) Validate() error {
    45  	return validate.Struct(req)
    46  }
    47  
    48  func (req *ApplyRequest) Builder(caller sacloud.APICaller) (*Builder, error) {
    49  	b := &Builder{Client: sacloud.NewLoadBalancerOp(caller)}
    50  	if err := service.RequestConvertTo(req, b); err != nil {
    51  		return nil, err
    52  	}
    53  	return b, nil
    54  }