@@ -29,7 +29,9 @@ import (
29
29
)
30
30
31
31
const (
32
- googleDiscoveryURL = "https://www.googleapis.com/discovery/v1/apis"
32
+ googleDiscoveryURL = "https://www.googleapis.com/discovery/v1/apis"
33
+ googleDefaultUniverse = "googleapis.com"
34
+ universeDomainPlaceholder = "UNIVERSE_DOMAIN"
33
35
)
34
36
35
37
var (
@@ -498,6 +500,14 @@ func (a *API) apiBaseURL() string {
498
500
return resolveRelative (base , rel )
499
501
}
500
502
503
+ // apiBaseURLTemplate returns the value returned by apiBaseURL with the
504
+ // Google Default Universe (googleapis.com) replaced with the placeholder
505
+ // UNIVERSE_DOMAIN for universe domain substitution.
506
+ func (a * API ) apiBaseURLTemplate () (string , error ) {
507
+ base := a .apiBaseURL ()
508
+ return strings .Replace (base , googleDefaultUniverse , universeDomainPlaceholder , 1 ), nil
509
+ }
510
+
501
511
func (a * API ) mtlsAPIBaseURL () string {
502
512
if a .doc .MTLSRootURL != "" {
503
513
return resolveRelative (a .doc .MTLSRootURL , a .doc .ServicePath )
@@ -760,9 +770,15 @@ func (a *API) GenerateCode() ([]byte, error) {
760
770
pn ("const apiName = %q" , a .doc .Name )
761
771
pn ("const apiVersion = %q" , a .doc .Version )
762
772
pn ("const basePath = %q" , a .apiBaseURL ())
773
+ basePathTemplate , err := a .apiBaseURLTemplate ()
774
+ if err != nil {
775
+ return buf .Bytes (), err
776
+ }
777
+ pn ("const basePathTemplate = %q" , basePathTemplate )
763
778
if mtlsBase := a .mtlsAPIBaseURL (); mtlsBase != "" {
764
779
pn ("const mtlsBasePath = %q" , mtlsBase )
765
780
}
781
+ pn ("const defaultUniverseDomain = \" googleapis.com\" " )
766
782
767
783
a .generateScopeConstants ()
768
784
a .PopulateSchemas ()
@@ -785,9 +801,11 @@ func (a *API) GenerateCode() ([]byte, error) {
785
801
pn ("opts = append([]option.ClientOption{scopesOption}, opts...)" )
786
802
}
787
803
pn ("opts = append(opts, internaloption.WithDefaultEndpoint(basePath))" )
804
+ pn ("opts = append(opts, internaloption.WithDefaultEndpointTemplate(basePathTemplate))" )
788
805
if a .mtlsAPIBaseURL () != "" {
789
806
pn ("opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath))" )
790
807
}
808
+ pn ("opts = append(opts, internaloption.WithDefaultUniverseDomain(defaultUniverseDomain))" )
791
809
pn ("client, endpoint, err := htransport.NewClient(ctx, opts...)" )
792
810
pn ("if err != nil { return nil, err }" )
793
811
pn ("s, err := New(client)" )
0 commit comments