@@ -8,95 +8,95 @@ import (
88 "time"
99)
1010
11- type ApiHost struct {
11+ type APIHost struct {
1212 BaseRESTURL * url.URL
1313 GraphqlURL * url.URL
1414 UploadURL * url.URL
1515 RawURL * url.URL
1616}
1717
18- func newDotcomHost () (ApiHost , error ) {
18+ func newDotcomHost () (APIHost , error ) {
1919 baseRestURL , err := url .Parse ("https://api.github.com/" )
2020 if err != nil {
21- return ApiHost {}, fmt .Errorf ("failed to parse dotcom REST URL: %w" , err )
21+ return APIHost {}, fmt .Errorf ("failed to parse dotcom REST URL: %w" , err )
2222 }
2323
2424 gqlURL , err := url .Parse ("https://api.github.com/graphql" )
2525 if err != nil {
26- return ApiHost {}, fmt .Errorf ("failed to parse dotcom GraphQL URL: %w" , err )
26+ return APIHost {}, fmt .Errorf ("failed to parse dotcom GraphQL URL: %w" , err )
2727 }
2828
2929 uploadURL , err := url .Parse ("https://uploads.github.com" )
3030 if err != nil {
31- return ApiHost {}, fmt .Errorf ("failed to parse dotcom Upload URL: %w" , err )
31+ return APIHost {}, fmt .Errorf ("failed to parse dotcom Upload URL: %w" , err )
3232 }
3333
3434 rawURL , err := url .Parse ("https://raw.githubusercontent.com/" )
3535 if err != nil {
36- return ApiHost {}, fmt .Errorf ("failed to parse dotcom Raw URL: %w" , err )
36+ return APIHost {}, fmt .Errorf ("failed to parse dotcom Raw URL: %w" , err )
3737 }
3838
39- return ApiHost {
39+ return APIHost {
4040 BaseRESTURL : baseRestURL ,
4141 GraphqlURL : gqlURL ,
4242 UploadURL : uploadURL ,
4343 RawURL : rawURL ,
4444 }, nil
4545}
4646
47- func newGHECHost (hostname string ) (ApiHost , error ) {
47+ func newGHECHost (hostname string ) (APIHost , error ) {
4848 u , err := url .Parse (hostname )
4949 if err != nil {
50- return ApiHost {}, fmt .Errorf ("failed to parse GHEC URL: %w" , err )
50+ return APIHost {}, fmt .Errorf ("failed to parse GHEC URL: %w" , err )
5151 }
5252
5353 // Unsecured GHEC would be an error
5454 if u .Scheme == "http" {
55- return ApiHost {}, fmt .Errorf ("GHEC URL must be HTTPS" )
55+ return APIHost {}, fmt .Errorf ("GHEC URL must be HTTPS" )
5656 }
5757
5858 restURL , err := url .Parse (fmt .Sprintf ("https://api.%s/" , u .Hostname ()))
5959 if err != nil {
60- return ApiHost {}, fmt .Errorf ("failed to parse GHEC REST URL: %w" , err )
60+ return APIHost {}, fmt .Errorf ("failed to parse GHEC REST URL: %w" , err )
6161 }
6262
6363 gqlURL , err := url .Parse (fmt .Sprintf ("https://api.%s/graphql" , u .Hostname ()))
6464 if err != nil {
65- return ApiHost {}, fmt .Errorf ("failed to parse GHEC GraphQL URL: %w" , err )
65+ return APIHost {}, fmt .Errorf ("failed to parse GHEC GraphQL URL: %w" , err )
6666 }
6767
6868 uploadURL , err := url .Parse (fmt .Sprintf ("https://uploads.%s" , u .Hostname ()))
6969 if err != nil {
70- return ApiHost {}, fmt .Errorf ("failed to parse GHEC Upload URL: %w" , err )
70+ return APIHost {}, fmt .Errorf ("failed to parse GHEC Upload URL: %w" , err )
7171 }
7272
7373 rawURL , err := url .Parse (fmt .Sprintf ("https://raw.%s/" , u .Hostname ()))
7474 if err != nil {
75- return ApiHost {}, fmt .Errorf ("failed to parse GHEC Raw URL: %w" , err )
75+ return APIHost {}, fmt .Errorf ("failed to parse GHEC Raw URL: %w" , err )
7676 }
7777
78- return ApiHost {
78+ return APIHost {
7979 BaseRESTURL : restURL ,
8080 GraphqlURL : gqlURL ,
8181 UploadURL : uploadURL ,
8282 RawURL : rawURL ,
8383 }, nil
8484}
8585
86- func newGHESHost (hostname string ) (ApiHost , error ) {
86+ func newGHESHost (hostname string ) (APIHost , error ) {
8787 u , err := url .Parse (hostname )
8888 if err != nil {
89- return ApiHost {}, fmt .Errorf ("failed to parse GHES URL: %w" , err )
89+ return APIHost {}, fmt .Errorf ("failed to parse GHES URL: %w" , err )
9090 }
9191
9292 restURL , err := url .Parse (fmt .Sprintf ("%s://%s/api/v3/" , u .Scheme , u .Hostname ()))
9393 if err != nil {
94- return ApiHost {}, fmt .Errorf ("failed to parse GHES REST URL: %w" , err )
94+ return APIHost {}, fmt .Errorf ("failed to parse GHES REST URL: %w" , err )
9595 }
9696
9797 gqlURL , err := url .Parse (fmt .Sprintf ("%s://%s/api/graphql" , u .Scheme , u .Hostname ()))
9898 if err != nil {
99- return ApiHost {}, fmt .Errorf ("failed to parse GHES GraphQL URL: %w" , err )
99+ return APIHost {}, fmt .Errorf ("failed to parse GHES GraphQL URL: %w" , err )
100100 }
101101
102102 // Check if subdomain isolation is enabled
@@ -112,7 +112,7 @@ func newGHESHost(hostname string) (ApiHost, error) {
112112 uploadURL , err = url .Parse (fmt .Sprintf ("%s://%s/api/uploads/" , u .Scheme , u .Hostname ()))
113113 }
114114 if err != nil {
115- return ApiHost {}, fmt .Errorf ("failed to parse GHES Upload URL: %w" , err )
115+ return APIHost {}, fmt .Errorf ("failed to parse GHES Upload URL: %w" , err )
116116 }
117117
118118 var rawURL * url.URL
@@ -124,10 +124,10 @@ func newGHESHost(hostname string) (ApiHost, error) {
124124 rawURL , err = url .Parse (fmt .Sprintf ("%s://%s/raw/" , u .Scheme , u .Hostname ()))
125125 }
126126 if err != nil {
127- return ApiHost {}, fmt .Errorf ("failed to parse GHES Raw URL: %w" , err )
127+ return APIHost {}, fmt .Errorf ("failed to parse GHES Raw URL: %w" , err )
128128 }
129129
130- return ApiHost {
130+ return APIHost {
131131 BaseRESTURL : restURL ,
132132 GraphqlURL : gqlURL ,
133133 UploadURL : uploadURL ,
@@ -159,18 +159,18 @@ func checkSubdomainIsolation(scheme, hostname string) bool {
159159}
160160
161161// Note that this does not handle ports yet, so development environments are out.
162- func ParseAPIHost (s string ) (ApiHost , error ) {
162+ func ParseAPIHost (s string ) (APIHost , error ) {
163163 if s == "" {
164164 return newDotcomHost ()
165165 }
166166
167167 u , err := url .Parse (s )
168168 if err != nil {
169- return ApiHost {}, fmt .Errorf ("could not parse host as URL: %s" , s )
169+ return APIHost {}, fmt .Errorf ("could not parse host as URL: %s" , s )
170170 }
171171
172172 if u .Scheme == "" {
173- return ApiHost {}, fmt .Errorf ("host must have a scheme (http or https): %s" , s )
173+ return APIHost {}, fmt .Errorf ("host must have a scheme (http or https): %s" , s )
174174 }
175175
176176 if strings .HasSuffix (u .Hostname (), "github.com" ) {
0 commit comments