Skip to content

Commit 71c4d43

Browse files
committedSep 24, 2019
fix some golint issues
1 parent a66a118 commit 71c4d43

5 files changed

+42
-41
lines changed
 

‎client.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/golang/glog"
1010
)
1111

12-
// Client configuration options
12+
// Options : Client configuration options
1313
type Options struct {
1414
URL *url.URL // URL to the CAS service
1515
Store TicketStore // Custom TicketStore, if nil a MemoryStore will be used
@@ -199,7 +199,7 @@ func (c *Client) RedirectToLogout(w http.ResponseWriter, r *http.Request) {
199199
http.Redirect(w, r, u, http.StatusFound)
200200
}
201201

202-
// RedirectToLogout replies to the request with a redirect URL to authenticate with CAS.
202+
// RedirectToLogin replies to the request with a redirect URL to authenticate with CAS.
203203
func (c *Client) RedirectToLogin(w http.ResponseWriter, r *http.Request) {
204204
u, err := c.LoginUrlForRequest(r)
205205
if err != nil {
@@ -216,12 +216,12 @@ func (c *Client) RedirectToLogin(w http.ResponseWriter, r *http.Request) {
216216

217217
// validateTicket performs CAS ticket validation with the given ticket and service.
218218
func (c *Client) validateTicket(ticket string, service *http.Request) error {
219-
serviceUrl, err := requestURL(service)
219+
serviceURL, err := requestURL(service)
220220
if err != nil {
221221
return err
222222
}
223223

224-
success, err := c.stValidator.ValidateTicket(serviceUrl, ticket)
224+
success, err := c.stValidator.ValidateTicket(serviceURL, ticket)
225225
if err != nil {
226226
return err
227227
}

‎example_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
7272

7373
w.Header().Add("Content-Type", "text/html")
7474

75-
tmpl, err := template.New("index.html").Parse(index_html)
75+
tmpl, err := template.New("index.html").Parse(indexHTML)
7676

7777
if err != nil {
7878
w.WriteHeader(http.StatusInternalServerError)
79-
fmt.Fprintf(w, error_500, err)
79+
fmt.Fprintf(w, error500, err)
8080
return
8181
}
8282

@@ -88,14 +88,14 @@ func (h *myHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
8888
html := new(bytes.Buffer)
8989
if err := tmpl.Execute(html, binding); err != nil {
9090
w.WriteHeader(http.StatusInternalServerError)
91-
fmt.Fprintf(w, error_500, err)
91+
fmt.Fprintf(w, error500, err)
9292
return
9393
}
9494

9595
html.WriteTo(w)
9696
}
9797

98-
const index_html = `<!DOCTYPE html>
98+
const indexHTML = `<!DOCTYPE html>
9999
<html>
100100
<head>
101101
<title>Welcome {{.Username}}</title>
@@ -114,7 +114,7 @@ const index_html = `<!DOCTYPE html>
114114
</html>
115115
`
116116

117-
const error_500 = `<!DOCTYPE html>
117+
const error500 = `<!DOCTYPE html>
118118
<html>
119119
<head>
120120
<title>Error 500</title>

‎http_helpers.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func setClient(r *http.Request, c *Client) {
2424
func getClient(r *http.Request) *Client {
2525
if c := r.Context().Value(clientKey); c != nil {
2626
return c.(*Client)
27-
} else {
28-
return nil // explicitly pass along the nil to caller -- conforms to previous impl
2927
}
28+
29+
return nil // explicitly pass along the nil to caller -- conforms to previous impl
3030
}
3131

3232
// RedirectToLogin allows CAS protected handlers to redirect a request
@@ -68,9 +68,9 @@ func setAuthenticationResponse(r *http.Request, a *AuthenticationResponse) {
6868
func getAuthenticationResponse(r *http.Request) *AuthenticationResponse {
6969
if a := r.Context().Value(authenticationResponseKey); a != nil {
7070
return a.(*AuthenticationResponse)
71-
} else {
72-
return nil // explicitly pass along the nil to caller -- conforms to previous impl
7371
}
72+
73+
return nil // explicitly pass along the nil to caller -- conforms to previous impl
7474
}
7575

7676
// IsAuthenticated indicates whether the request has been authenticated with CAS.

‎rest_client_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ func TestRequestGrantingTicket(t *testing.T) {
2929
}))
3030
defer server.Close()
3131

32-
casUrl, err := url.Parse(server.URL + "/cas/")
32+
casURL, err := url.Parse(server.URL + "/cas/")
3333
if err != nil {
3434
t.Error("failed to create cas url from test server")
3535
}
3636

3737
restClient := NewRestClient(&RestOptions{
38-
CasURL: casUrl,
38+
CasURL: casURL,
3939
Client: server.Client(),
4040
})
4141

@@ -76,20 +76,20 @@ func TestRequestServiceTicket(t *testing.T) {
7676
}))
7777
defer server.Close()
7878

79-
casUrl, err := url.Parse(server.URL + "/cas/")
79+
casURL, err := url.Parse(server.URL + "/cas/")
8080
if err != nil {
8181
t.Error("failed to create cas url from test server")
8282
}
8383

8484

85-
serviceUrl, err := url.Parse("https://hitchhiker.com/heartOfGold")
85+
serviceURL, err := url.Parse("https://hitchhiker.com/heartOfGold")
8686
if err != nil {
8787
t.Error("failed to create service url")
8888
}
8989

9090
restClient := NewRestClient(&RestOptions{
91-
CasURL: casUrl,
92-
ServiceURL: serviceUrl,
91+
CasURL: casURL,
92+
ServiceURL: serviceURL,
9393
Client: server.Client(),
9494
})
9595

@@ -107,14 +107,14 @@ func TestRequestServiceTicket(t *testing.T) {
107107
t.Errorf("service ticket request should fail for TGT-xyz")
108108
}
109109

110-
serviceUrl, err = url.Parse("https://hitchhiker.com/restaurantAtTheEndOfTheUniverse")
110+
serviceURL, err = url.Parse("https://hitchhiker.com/restaurantAtTheEndOfTheUniverse")
111111
if err != nil {
112112
t.Error("failed to create service url")
113113
}
114114

115115
restClient = NewRestClient(&RestOptions{
116-
CasURL: casUrl,
117-
ServiceURL: serviceUrl,
116+
CasURL: casURL,
117+
ServiceURL: serviceURL,
118118
Client: server.Client(),
119119
})
120120

@@ -135,13 +135,13 @@ func TestValidateService(t *testing.T) {
135135
}))
136136
defer server.Close()
137137

138-
casUrl, err := url.Parse(server.URL + "/cas/")
138+
casURL, err := url.Parse(server.URL + "/cas/")
139139
if err != nil {
140140
t.Error("failed to create cas url from test server")
141141
}
142142

143143
restClient := NewRestClient(&RestOptions{
144-
CasURL: casUrl,
144+
CasURL: casURL,
145145
Client: server.Client(),
146146
})
147147

@@ -167,13 +167,13 @@ func TestLogout(t *testing.T) {
167167
}))
168168
defer server.Close()
169169

170-
casUrl, err := url.Parse(server.URL + "/cas/")
170+
casURL, err := url.Parse(server.URL + "/cas/")
171171
if err != nil {
172172
t.Error("failed to create cas url from test server")
173173
}
174174

175175
restClient := NewRestClient(&RestOptions{
176-
CasURL: casUrl,
176+
CasURL: casURL,
177177
Client: server.Client(),
178178
})
179179

‎service_validate.go

+16-15
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,29 @@ import (
1010
"github.com/golang/glog"
1111
)
1212

13-
func NewServiceTicketValidator(client *http.Client, casUrl *url.URL) *ServiceTicketValidator {
13+
// NewServiceTicketValidator create a new *ServiceTicketValidator
14+
func NewServiceTicketValidator(client *http.Client, casURL *url.URL) *ServiceTicketValidator {
1415
return &ServiceTicketValidator{
1516
client: client,
16-
casUrl: casUrl,
17+
casURL: casURL,
1718
}
1819
}
1920

2021
// ServiceTicketValidator is responsible for the validation of a service ticket
2122
type ServiceTicketValidator struct {
2223
client *http.Client
23-
casUrl *url.URL
24+
casURL *url.URL
2425
}
2526

2627
// ValidateTicket validates the service ticket for the given server. The method will try to use the service validate
2728
// endpoint of the cas >= 2 protocol, if the service validate endpoint not available, the function will use the cas 1
2829
// validate endpoint.
29-
func (validator *ServiceTicketValidator) ValidateTicket(serviceUrl *url.URL, ticket string) (*AuthenticationResponse, error) {
30+
func (validator *ServiceTicketValidator) ValidateTicket(serviceURL *url.URL, ticket string) (*AuthenticationResponse, error) {
3031
if glog.V(2) {
31-
glog.Infof("Validating ticket %v for service %v", ticket, serviceUrl)
32+
glog.Infof("Validating ticket %v for service %v", ticket, serviceURL)
3233
}
3334

34-
u, err := validator.ServiceValidateUrl(serviceUrl, ticket)
35+
u, err := validator.ServiceValidateUrl(serviceURL, ticket)
3536
if err != nil {
3637
return nil, err
3738
}
@@ -59,7 +60,7 @@ func (validator *ServiceTicketValidator) ValidateTicket(serviceUrl *url.URL, tic
5960
}
6061

6162
if resp.StatusCode == http.StatusNotFound {
62-
return validator.validateTicketCas1(serviceUrl, ticket)
63+
return validator.validateTicketCas1(serviceURL, ticket)
6364
}
6465

6566
body, err := ioutil.ReadAll(resp.Body)
@@ -91,22 +92,22 @@ func (validator *ServiceTicketValidator) ValidateTicket(serviceUrl *url.URL, tic
9192

9293
// ServiceValidateUrl creates the service validation url for the cas >= 2 protocol.
9394
// TODO the function is only exposed, because of the clients ServiceValidateUrl function
94-
func (validator *ServiceTicketValidator) ServiceValidateUrl(serviceUrl *url.URL, ticket string) (string, error) {
95-
u, err := validator.casUrl.Parse(path.Join(validator.casUrl.Path, "serviceValidate"))
95+
func (validator *ServiceTicketValidator) ServiceValidateUrl(serviceURL *url.URL, ticket string) (string, error) {
96+
u, err := validator.casURL.Parse(path.Join(validator.casURL.Path, "serviceValidate"))
9697
if err != nil {
9798
return "", err
9899
}
99100

100101
q := u.Query()
101-
q.Add("service", sanitisedURLString(serviceUrl))
102+
q.Add("service", sanitisedURLString(serviceURL))
102103
q.Add("ticket", ticket)
103104
u.RawQuery = q.Encode()
104105

105106
return u.String(), nil
106107
}
107108

108-
func (validator *ServiceTicketValidator) validateTicketCas1(serviceUrl *url.URL, ticket string) (*AuthenticationResponse, error) {
109-
u, err := validator.ValidateUrl(serviceUrl, ticket)
109+
func (validator *ServiceTicketValidator) validateTicketCas1(serviceURL *url.URL, ticket string) (*AuthenticationResponse, error) {
110+
u, err := validator.ValidateUrl(serviceURL, ticket)
110111
if err != nil {
111112
return nil, err
112113
}
@@ -167,14 +168,14 @@ func (validator *ServiceTicketValidator) validateTicketCas1(serviceUrl *url.URL,
167168

168169
// ValidateUrl creates the validation url for the cas >= 1 protocol.
169170
// TODO the function is only exposed, because of the clients ValidateUrl function
170-
func (validator *ServiceTicketValidator) ValidateUrl(serviceUrl *url.URL, ticket string) (string, error) {
171-
u, err := validator.casUrl.Parse(path.Join(validator.casUrl.Path, "validate"))
171+
func (validator *ServiceTicketValidator) ValidateUrl(serviceURL *url.URL, ticket string) (string, error) {
172+
u, err := validator.casURL.Parse(path.Join(validator.casURL.Path, "validate"))
172173
if err != nil {
173174
return "", err
174175
}
175176

176177
q := u.Query()
177-
q.Add("service", sanitisedURLString(serviceUrl))
178+
q.Add("service", sanitisedURLString(serviceURL))
178179
q.Add("ticket", ticket)
179180
u.RawQuery = q.Encode()
180181

0 commit comments

Comments
 (0)
Please sign in to comment.