• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

softlayer / softlayer-go / 13824212013

13 Mar 2025 12:26AM UTC coverage: 95.953% (-2.2%) from 98.143%
13824212013

Pull #201

github

web-flow
Merge 0268bb9e4 into 80a745b76
Pull Request #201: Bump golang.org/x/net from 0.23.0 to 0.36.0

36825 of 38378 relevant lines covered (95.95%)

7.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/helpers/location/location.go
1
/**
2
 * Copyright 2016 IBM Corp.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *    http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package location
18

19
import (
20
        "fmt"
21

22
        "github.com/softlayer/softlayer-go/datatypes"
23
        "github.com/softlayer/softlayer-go/filter"
24
        "github.com/softlayer/softlayer-go/services"
25
        "github.com/softlayer/softlayer-go/session"
26
)
27

28
// GetLocationByName returns a Location that matches the provided name, or an
29
// error if no matching Location can be found.
30
//
31
// If you need to access a datacenter's unique properties, use
32
// GetDatacenterByName instead
33
func GetLocationByName(sess *session.Session, name string, args ...interface{}) (datatypes.Location, error) {
×
34
        var mask string
×
35
        if len(args) > 0 {
×
36
                mask = args[0].(string)
×
37
        }
×
38

39
        locs, err := services.GetLocationService(sess).
×
40
                Mask(mask).
×
41
                Filter(filter.New(filter.Path("name").Eq(name)).Build()).
×
42
                GetDatacenters()
×
43

×
44
        if err != nil {
×
45
                return datatypes.Location{}, err
×
46
        }
×
47

48
        // An empty filtered result set does not raise an error
49
        if len(locs) == 0 {
×
50
                return datatypes.Location{}, fmt.Errorf("No locations found with name of %s", name)
×
51
        }
×
52

53
        return locs[0], nil
×
54
}
55

56
// GetDatacenterByName returns a Location_Datacenter that matches the provided
57
// name, or an error if no matching datacenter can be found.
58
//
59
// Note that unless you need to access datacenter-specific properties
60
// (backendHardwareRouters, etc.), it is more efficient to use
61
// GetLocationByName, since GetDatacenterByName requires an extra call to the
62
// API
63
func GetDatacenterByName(sess *session.Session, name string, args ...interface{}) (datatypes.Location_Datacenter, error) {
×
64
        var mask string
×
65
        if len(args) > 0 {
×
66
                mask = args[0].(string)
×
67
        }
×
68

69
        // SoftLayer does not provide a direct path to retrieve a list of "Location_Datacenter"
70
        // objects. Location_Datacenter.getDatacenters() actually returns a list of "Location"
71
        // objects, which do not have datacenter-specific properties populated.  So we do this
72
        // in two passes
73

74
        // First get the Location which matches the name
75
        location, err := GetLocationByName(sess, name, "mask[id]")
×
76

×
77
        if err != nil {
×
78
                return datatypes.Location_Datacenter{}, err
×
79
        }
×
80

81
        // Now get the Datacenter record itself.
82
        return services.GetLocationDatacenterService(sess).
×
83
                Id(*location.Id).
×
84
                Mask(mask).
×
85
                GetObject()
×
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc