Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a202aadc
Commit
a202aadc
authored
Jan 13, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use api.NewAPI instead of lazy initialization
parent
d9014671
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
21 deletions
+20
-21
authorization_test.go
authorization_test.go
+1
-1
internal/api/api.go
internal/api/api.go
+14
-15
internal/upstream/routes.go
internal/upstream/routes.go
+5
-5
No files found.
authorization_test.go
View file @
a202aadc
...
...
@@ -25,7 +25,7 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
a
:=
&
api
.
API
{
URL
:
helper
.
URLMustParse
(
ts
.
URL
),
Version
:
"123"
}
a
:=
api
.
NewAPI
(
helper
.
URLMustParse
(
ts
.
URL
),
"123"
,
nil
)
response
:=
httptest
.
NewRecorder
()
a
.
PreAuthorizeHandler
(
okHandler
,
suffix
)
.
ServeHTTP
(
response
,
httpRequest
)
...
...
internal/api/api.go
View file @
a202aadc
...
...
@@ -11,25 +11,24 @@ import (
"net/http"
"net/url"
"strings"
"sync"
)
type
API
struct
{
_client
*
http
.
Client
configureClientOnce
sync
.
Once
URL
*
url
.
URL
Version
string
RoundTripper
*
badgateway
.
RoundTripper
Client
*
http
.
Client
URL
*
url
.
URL
Version
string
}
func
(
a
*
API
)
client
()
*
http
.
Client
{
a
.
configureClientOnce
.
Do
(
func
()
{
a
.
_client
=
&
http
.
Client
{
Transport
:
&
badgateway
.
RoundTripper
{}}
if
a
.
RoundTripper
!=
nil
{
a
.
_client
.
Transport
=
a
.
RoundTripper
}
})
return
a
.
_client
func
NewAPI
(
myURL
*
url
.
URL
,
version
string
,
roundtripper
*
badgateway
.
RoundTripper
)
*
API
{
a
:=
API
{
Client
:
&
http
.
Client
{
Transport
:
&
badgateway
.
RoundTripper
{}},
URL
:
myURL
,
Version
:
version
,
}
if
roundtripper
!=
nil
{
a
.
Client
.
Transport
=
roundtripper
}
return
&
a
}
type
HandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
Response
)
...
...
@@ -113,7 +112,7 @@ func (api *API) PreAuthorizeHandler(h HandleFunc, suffix string) http.Handler {
return
}
authResponse
,
err
:=
api
.
client
()
.
Do
(
authReq
)
authResponse
,
err
:=
api
.
Client
.
Do
(
authReq
)
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"preAuthorizeHandler: do %v: %v"
,
authReq
.
URL
.
Path
,
err
))
return
...
...
internal/upstream/routes.go
View file @
a202aadc
...
...
@@ -31,11 +31,11 @@ const ciAPIPattern = `^/ci/api/`
// see upstream.ServeHTTP
func
(
u
*
Upstream
)
configureRoutes
()
{
api
:=
&
apipkg
.
API
{
RoundTripper
:
u
.
RoundTripper
()
,
URL
:
u
.
Backend
,
Version
:
u
.
Version
,
}
api
:=
apipkg
.
NewAPI
(
u
.
Backend
,
u
.
Version
,
u
.
RoundTripper
()
,
)
static
:=
&
staticpages
.
Static
{
u
.
DocumentRoot
}
proxy
:=
&
proxypkg
.
Proxy
{
URL
:
u
.
Backend
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment