1 // Copyright 2022-2025 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 type LoadBalancerServers []*LoadBalancerServer
18 19 // AddGSLBServer サーバの追加
20 func (o *LoadBalancerServers) Add(server *LoadBalancerServer) {
21 if o.Exist(server) {
22 return // noop if already exists
23 }
24 *o = append(*o, server)
25 }
26 27 // Exist サーバの存在確認
28 func (o *LoadBalancerServers) Exist(server *LoadBalancerServer) bool {
29 for _, v := range *o {
30 if v.IPAddress == server.IPAddress {
31 return true
32 }
33 }
34 return false
35 }
36 37 // ExistAt サーバの存在確認
38 func (o *LoadBalancerServers) ExistAt(ip string) bool {
39 return o.Exist(&LoadBalancerServer{IPAddress: ip})
40 }
41 42 // Find サーバの検索
43 func (o *LoadBalancerServers) Find(server *LoadBalancerServer) *LoadBalancerServer {
44 for _, v := range *o {
45 if v.IPAddress == server.IPAddress {
46 return v
47 }
48 }
49 return nil
50 }
51 52 // FindAt サーバの検索
53 func (o *LoadBalancerServers) FindAt(ip string) *LoadBalancerServer {
54 return o.Find(&LoadBalancerServer{IPAddress: ip})
55 }
56 57 // Update サーバの更新
58 func (o *LoadBalancerServers) Update(old *LoadBalancerServer, new *LoadBalancerServer) {
59 for _, v := range *o {
60 if v.IPAddress == old.IPAddress {
61 *v = *new
62 return
63 }
64 }
65 }
66 67 // UpdateAt サーバの更新
68 func (o *LoadBalancerServers) UpdateAt(ip string, new *LoadBalancerServer) {
69 o.Update(&LoadBalancerServer{IPAddress: ip}, new)
70 }
71 72 // Delete サーバの削除
73 func (o *LoadBalancerServers) Delete(server *LoadBalancerServer) {
74 var res []*LoadBalancerServer
75 for _, v := range *o {
76 if v.IPAddress != server.IPAddress {
77 res = append(res, v)
78 }
79 }
80 *o = res
81 }
82 83 // DeleteAt サーバの削除
84 func (o *LoadBalancerServers) DeleteAt(ip string) {
85 o.Delete(&LoadBalancerServer{IPAddress: ip})
86 }
87