github.com/sacloud/iaas-api-go@v1.12.0/customize_dns.go (about) 1 // Copyright 2022-2023 The sacloud/iaas-api-go 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 iaas 16 17 import "github.com/sacloud/iaas-api-go/types" 18 19 type DNSRecords []*DNSRecord 20 21 // Add レコードを追加します。名前/タイプ/値が同じレコードが存在する場合は何もしません 22 func (o *DNSRecords) Add(rs ...*DNSRecord) { 23 for _, r := range rs { 24 if o.Exist(r) { 25 continue 26 } 27 *o = append(*o, r) 28 } 29 } 30 31 // Delete 名前/タイプ/値が同じレコードを削除します 32 func (o *DNSRecords) Delete(rs ...*DNSRecord) { 33 var res []*DNSRecord 34 for _, cur := range *o { 35 remove := false 36 for _, r := range rs { 37 if cur.Equal(r) { 38 remove = true 39 break 40 } 41 } 42 if !remove { 43 res = append(res, cur) 44 } 45 } 46 *o = res 47 } 48 49 // Find 名前/タイプ/値が同じレコードを返す 50 func (o *DNSRecords) Find(name string, tp types.EDNSRecordType, rdata string) *DNSRecord { 51 for _, r := range *o { 52 if r.Equal(&DNSRecord{Name: name, Type: tp, RData: rdata}) { 53 return r 54 } 55 } 56 return nil 57 } 58 59 // Exist 名前/タイプ/値が同じレコードが存在する場合にtrueを返す 60 func (o *DNSRecords) Exist(record *DNSRecord) bool { 61 if record == nil { 62 return false 63 } 64 for _, r := range *o { 65 if r.Equal(record) { 66 return true 67 } 68 } 69 return false 70 }