@@ -182,9 +182,10 @@ func v3auth(client *gophercloud.ProviderClient, endpoint string, opts tokens3.Au
182182// NewIdentityV2 creates a ServiceClient that may be used to interact with the v2 identity service.
183183func NewIdentityV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
184184 endpoint := client .IdentityBase + "v2.0/"
185+ clientType := "identity"
185186 var err error
186187 if ! reflect .DeepEqual (eo , gophercloud.EndpointOpts {}) {
187- eo .ApplyDefaults ("identity" )
188+ eo .ApplyDefaults (clientType )
188189 endpoint , err = client .EndpointLocator (eo )
189190 if err != nil {
190191 return nil , err
@@ -194,15 +195,17 @@ func NewIdentityV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOp
194195 return & gophercloud.ServiceClient {
195196 ProviderClient : client ,
196197 Endpoint : endpoint ,
198+ Type : clientType ,
197199 }, nil
198200}
199201
200202// NewIdentityV3 creates a ServiceClient that may be used to access the v3 identity service.
201203func NewIdentityV3 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
202204 endpoint := client .IdentityBase + "v3/"
205+ clientType := "identity"
203206 var err error
204207 if ! reflect .DeepEqual (eo , gophercloud.EndpointOpts {}) {
205- eo .ApplyDefaults ("identity" )
208+ eo .ApplyDefaults (clientType )
206209 endpoint , err = client .EndpointLocator (eo )
207210 if err != nil {
208211 return nil , err
@@ -212,125 +215,81 @@ func NewIdentityV3(client *gophercloud.ProviderClient, eo gophercloud.EndpointOp
212215 return & gophercloud.ServiceClient {
213216 ProviderClient : client ,
214217 Endpoint : endpoint ,
218+ Type : clientType ,
215219 }, nil
216220}
217221
218- // NewObjectStorageV1 creates a ServiceClient that may be used with the v1 object storage package.
219- func NewObjectStorageV1 ( client * gophercloud. ProviderClient , eo gophercloud. EndpointOpts ) ( * gophercloud.ServiceClient , error ) {
220- eo .ApplyDefaults ("object-store" )
222+ func initClientOpts ( client * gophercloud. ProviderClient , eo gophercloud. EndpointOpts , clientType string ) ( * gophercloud. ServiceClient , error ) {
223+ sc := new ( gophercloud.ServiceClient )
224+ eo .ApplyDefaults (clientType )
221225 url , err := client .EndpointLocator (eo )
222226 if err != nil {
223- return nil , err
227+ return sc , err
224228 }
225- return & gophercloud.ServiceClient {ProviderClient : client , Endpoint : url }, nil
229+ sc .ProviderClient = client
230+ sc .Endpoint = url
231+ sc .Type = clientType
232+ return sc , nil
233+ }
234+
235+ // NewObjectStorageV1 creates a ServiceClient that may be used with the v1 object storage package.
236+ func NewObjectStorageV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
237+ return initClientOpts (client , eo , "object-store" )
226238}
227239
228240// NewComputeV2 creates a ServiceClient that may be used with the v2 compute package.
229241func NewComputeV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
230- eo .ApplyDefaults ("compute" )
231- url , err := client .EndpointLocator (eo )
232- if err != nil {
233- return nil , err
234- }
235- return & gophercloud.ServiceClient {ProviderClient : client , Endpoint : url }, nil
242+ return initClientOpts (client , eo , "compute" )
236243}
237244
238245// NewNetworkV2 creates a ServiceClient that may be used with the v2 network package.
239246func NewNetworkV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
240- eo .ApplyDefaults ("network" )
241- url , err := client .EndpointLocator (eo )
242- if err != nil {
243- return nil , err
244- }
245- return & gophercloud.ServiceClient {
246- ProviderClient : client ,
247- Endpoint : url ,
248- ResourceBase : url + "v2.0/" ,
249- }, nil
247+ sc , err := initClientOpts (client , eo , "network" )
248+ sc .ResourceBase = sc .Endpoint + "v2.0/"
249+ return sc , err
250250}
251251
252252// NewBlockStorageV1 creates a ServiceClient that may be used to access the v1 block storage service.
253253func NewBlockStorageV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
254- eo .ApplyDefaults ("volume" )
255- url , err := client .EndpointLocator (eo )
256- if err != nil {
257- return nil , err
258- }
259- return & gophercloud.ServiceClient {ProviderClient : client , Endpoint : url }, nil
254+ return initClientOpts (client , eo , "volume" )
260255}
261256
262257// NewBlockStorageV2 creates a ServiceClient that may be used to access the v2 block storage service.
263258func NewBlockStorageV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
264- eo .ApplyDefaults ("volumev2" )
265- url , err := client .EndpointLocator (eo )
266- if err != nil {
267- return nil , err
268- }
269- return & gophercloud.ServiceClient {ProviderClient : client , Endpoint : url }, nil
259+ return initClientOpts (client , eo , "volumev2" )
270260}
271261
272262// NewSharedFileSystemV2 creates a ServiceClient that may be used to access the v2 shared file system service.
273263func NewSharedFileSystemV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
274- eo .ApplyDefaults ("sharev2" )
275- url , err := client .EndpointLocator (eo )
276- if err != nil {
277- return nil , err
278- }
279- return & gophercloud.ServiceClient {ProviderClient : client , Endpoint : url }, nil
264+ return initClientOpts (client , eo , "sharev2" )
280265}
281266
282267// NewCDNV1 creates a ServiceClient that may be used to access the OpenStack v1
283268// CDN service.
284269func NewCDNV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
285- eo .ApplyDefaults ("cdn" )
286- url , err := client .EndpointLocator (eo )
287- if err != nil {
288- return nil , err
289- }
290- return & gophercloud.ServiceClient {ProviderClient : client , Endpoint : url }, nil
270+ return initClientOpts (client , eo , "cdn" )
291271}
292272
293273// NewOrchestrationV1 creates a ServiceClient that may be used to access the v1 orchestration service.
294274func NewOrchestrationV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
295- eo .ApplyDefaults ("orchestration" )
296- url , err := client .EndpointLocator (eo )
297- if err != nil {
298- return nil , err
299- }
300- return & gophercloud.ServiceClient {ProviderClient : client , Endpoint : url }, nil
275+ return initClientOpts (client , eo , "orchestration" )
301276}
302277
303278// NewDBV1 creates a ServiceClient that may be used to access the v1 DB service.
304279func NewDBV1 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
305- eo .ApplyDefaults ("database" )
306- url , err := client .EndpointLocator (eo )
307- if err != nil {
308- return nil , err
309- }
310- return & gophercloud.ServiceClient {ProviderClient : client , Endpoint : url }, nil
280+ return initClientOpts (client , eo , "database" )
311281}
312282
313283// NewDNSV2 creates a ServiceClient that may be used to access the v2 DNS service.
314284func NewDNSV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
315- eo .ApplyDefaults ("dns" )
316- url , err := client .EndpointLocator (eo )
317- if err != nil {
318- return nil , err
319- }
320- return & gophercloud.ServiceClient {
321- ProviderClient : client ,
322- Endpoint : url ,
323- ResourceBase : url + "v2/" }, nil
285+ sc , err := initClientOpts (client , eo , "dns" )
286+ sc .ResourceBase = sc .Endpoint + "v2/"
287+ return sc , err
324288}
325289
326290// NewImageServiceV2 creates a ServiceClient that may be used to access the v2 image service.
327291func NewImageServiceV2 (client * gophercloud.ProviderClient , eo gophercloud.EndpointOpts ) (* gophercloud.ServiceClient , error ) {
328- eo .ApplyDefaults ("image" )
329- url , err := client .EndpointLocator (eo )
330- if err != nil {
331- return nil , err
332- }
333- return & gophercloud.ServiceClient {ProviderClient : client ,
334- Endpoint : url ,
335- ResourceBase : url + "v2/" }, nil
292+ sc , err := initClientOpts (client , eo , "image" )
293+ sc .ResourceBase = sc .Endpoint + "v2/"
294+ return sc , err
336295}
0 commit comments