github.com/sacloud/libsacloud/v2@v2.32.3/helper/service/internet/create_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 internet 16 17 import ( 18 "errors" 19 20 internetBuilder "github.com/sacloud/libsacloud/v2/helper/builder/internet" 21 "github.com/sacloud/libsacloud/v2/helper/validate" 22 "github.com/sacloud/libsacloud/v2/sacloud" 23 "github.com/sacloud/libsacloud/v2/sacloud/types" 24 ) 25 26 type CreateRequest struct { 27 Zone string `request:"-" validate:"required"` 28 29 Name string `validate:"required"` 30 Description string `validate:"min=0,max=512"` 31 Tags types.Tags 32 IconID types.ID 33 NetworkMaskLen int 34 BandWidthMbps int 35 EnableIPv6 bool 36 NoWait bool 37 NotFoundRetry int // スイッチ+ルータは作成直後だと404を返すことがあることへの対応でリトライする際のリトライ上限回数、省略時はDefaultNotFoundRetry 38 } 39 40 func (req *CreateRequest) Validate() error { 41 if err := validate.Struct(req); err != nil { 42 return err 43 } 44 if req.EnableIPv6 && req.NoWait { 45 return errors.New("NoWait=true is not supported when EnableIPv6=true") 46 } 47 return nil 48 } 49 50 func (req *CreateRequest) Builder(caller sacloud.APICaller) *internetBuilder.Builder { 51 return &internetBuilder.Builder{ 52 Name: req.Name, 53 Description: req.Description, 54 Tags: req.Tags, 55 IconID: req.IconID, 56 NetworkMaskLen: req.NetworkMaskLen, 57 BandWidthMbps: req.BandWidthMbps, 58 EnableIPv6: req.EnableIPv6, 59 NotFoundRetry: req.NotFoundRetry, 60 NoWait: req.NoWait, 61 Client: internetBuilder.NewAPIClient(caller), 62 } 63 }