Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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
0
Merge Requests
0
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
Kazuhiko Shiozaki
gitlab-workhorse
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
Show 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
...
@@ -25,7 +25,7 @@ func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, api
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
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
()
response
:=
httptest
.
NewRecorder
()
a
.
PreAuthorizeHandler
(
okHandler
,
suffix
)
.
ServeHTTP
(
response
,
httpRequest
)
a
.
PreAuthorizeHandler
(
okHandler
,
suffix
)
.
ServeHTTP
(
response
,
httpRequest
)
...
...
internal/api/api.go
View file @
a202aadc
...
@@ -11,25 +11,24 @@ import (
...
@@ -11,25 +11,24 @@ import (
"net/http"
"net/http"
"net/url"
"net/url"
"strings"
"strings"
"sync"
)
)
type
API
struct
{
type
API
struct
{
_client
*
http
.
Client
Client
*
http
.
Client
configureClientOnce
sync
.
Once
URL
*
url
.
URL
URL
*
url
.
URL
Version
string
Version
string
RoundTripper
*
badgateway
.
RoundTripper
}
}
func
(
a
*
API
)
client
()
*
http
.
Client
{
func
NewAPI
(
myURL
*
url
.
URL
,
version
string
,
roundtripper
*
badgateway
.
RoundTripper
)
*
API
{
a
.
configureClientOnce
.
Do
(
func
()
{
a
:=
API
{
a
.
_client
=
&
http
.
Client
{
Transport
:
&
badgateway
.
RoundTripper
{}}
Client
:
&
http
.
Client
{
Transport
:
&
badgateway
.
RoundTripper
{}},
if
a
.
RoundTripper
!=
nil
{
URL
:
myURL
,
a
.
_client
.
Transport
=
a
.
RoundTripper
Version
:
version
,
}
}
})
if
roundtripper
!=
nil
{
return
a
.
_client
a
.
Client
.
Transport
=
roundtripper
}
return
&
a
}
}
type
HandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
Response
)
type
HandleFunc
func
(
http
.
ResponseWriter
,
*
http
.
Request
,
*
Response
)
...
@@ -113,7 +112,7 @@ func (api *API) PreAuthorizeHandler(h HandleFunc, suffix string) http.Handler {
...
@@ -113,7 +112,7 @@ func (api *API) PreAuthorizeHandler(h HandleFunc, suffix string) http.Handler {
return
return
}
}
authResponse
,
err
:=
api
.
client
()
.
Do
(
authReq
)
authResponse
,
err
:=
api
.
Client
.
Do
(
authReq
)
if
err
!=
nil
{
if
err
!=
nil
{
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"preAuthorizeHandler: do %v: %v"
,
authReq
.
URL
.
Path
,
err
))
helper
.
Fail500
(
w
,
fmt
.
Errorf
(
"preAuthorizeHandler: do %v: %v"
,
authReq
.
URL
.
Path
,
err
))
return
return
...
...
internal/upstream/routes.go
View file @
a202aadc
...
@@ -31,11 +31,11 @@ const ciAPIPattern = `^/ci/api/`
...
@@ -31,11 +31,11 @@ const ciAPIPattern = `^/ci/api/`
// see upstream.ServeHTTP
// see upstream.ServeHTTP
func
(
u
*
Upstream
)
configureRoutes
()
{
func
(
u
*
Upstream
)
configureRoutes
()
{
api
:=
&
apipkg
.
API
{
api
:=
apipkg
.
NewAPI
(
RoundTripper
:
u
.
RoundTripper
()
,
u
.
Backend
,
URL
:
u
.
Backend
,
u
.
Version
,
Version
:
u
.
Version
,
u
.
RoundTripper
()
,
}
)
static
:=
&
staticpages
.
Static
{
u
.
DocumentRoot
}
static
:=
&
staticpages
.
Static
{
u
.
DocumentRoot
}
proxy
:=
&
proxypkg
.
Proxy
{
proxy
:=
&
proxypkg
.
Proxy
{
URL
:
u
.
Backend
,
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