Skip to content

Commit 6e250cc

Browse files
committed
Fix golint errors in users.go
1 parent 5c49be7 commit 6e250cc

File tree

1 file changed

+39
-42
lines changed

1 file changed

+39
-42
lines changed

users.go

+39-42
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@ import (
66
"sync"
77
)
88

9-
/*
10-
SecretProvider is used by authenticators. Takes user name and realm
11-
as an argument, returns secret required for authentication (HA1 for
12-
digest authentication, properly encrypted password for basic).
13-
14-
Returning an empty string means failing the authentication.
15-
*/
9+
// SecretProvider is used by authenticators. Takes user name and realm
10+
// as an argument, returns secret required for authentication (HA1 for
11+
// digest authentication, properly encrypted password for basic).
12+
//
13+
// Returning an empty string means failing the authentication.
1614
type SecretProvider func(user, realm string) string
1715

18-
/*
19-
Common functions for file auto-reloading
20-
*/
16+
// File handles automatic file reloading on changes.
2117
type File struct {
2218
Path string
2319
Info os.FileInfo
@@ -26,6 +22,11 @@ type File struct {
2622
mu sync.Mutex
2723
}
2824

25+
// ReloadIfNeeded checks file Stat and calls Reload() if any changes
26+
// were detected. File mutex is Locked for the duration of Reload()
27+
// call.
28+
//
29+
// This function will panic() if Stat fails.
2930
func (f *File) ReloadIfNeeded() {
3031
info, err := os.Stat(f.Path)
3132
if err != nil {
@@ -39,27 +40,26 @@ func (f *File) ReloadIfNeeded() {
3940
}
4041
}
4142

42-
/*
43-
Structure used for htdigest file authentication. Users map realms to
44-
maps of users to their HA1 digests.
45-
*/
43+
// HtdigestFile is a File holding htdigest authentication data.
4644
type HtdigestFile struct {
45+
// File is used for automatic reloading of the authentication data.
4746
File
47+
// Users is a map of realms to users to HA1 digests.
4848
Users map[string]map[string]string
4949
mu sync.RWMutex
5050
}
5151

52-
func reload_htdigest(hf *HtdigestFile) {
52+
func reloadHTDigest(hf *HtdigestFile) {
5353
r, err := os.Open(hf.Path)
5454
if err != nil {
5555
panic(err)
5656
}
57-
csv_reader := csv.NewReader(r)
58-
csv_reader.Comma = ':'
59-
csv_reader.Comment = '#'
60-
csv_reader.TrimLeadingSpace = true
57+
reader := csv.NewReader(r)
58+
reader.Comma = ':'
59+
reader.Comment = '#'
60+
reader.TrimLeadingSpace = true
6161

62-
records, err := csv_reader.ReadAll()
62+
records, err := reader.ReadAll()
6363
if err != nil {
6464
panic(err)
6565
}
@@ -76,14 +76,12 @@ func reload_htdigest(hf *HtdigestFile) {
7676
}
7777
}
7878

79-
/*
80-
SecretProvider implementation based on htdigest-formated files. Will
81-
reload htdigest file on changes. Will panic on syntax errors in
82-
htdigest files.
83-
*/
79+
// HtdigestFileProvider is a SecretProvider implementation based on
80+
// htdigest-formated files. It will automatically reload htdigest file
81+
// on changes. It panics on syntax errors in htdigest files.
8482
func HtdigestFileProvider(filename string) SecretProvider {
8583
hf := &HtdigestFile{File: File{Path: filename}}
86-
hf.Reload = func() { reload_htdigest(hf) }
84+
hf.Reload = func() { reloadHTDigest(hf) }
8785
return func(user, realm string) string {
8886
hf.ReloadIfNeeded()
8987
hf.mu.RLock()
@@ -100,27 +98,27 @@ func HtdigestFileProvider(filename string) SecretProvider {
10098
}
10199
}
102100

103-
/*
104-
Structure used for htdigest file authentication. Users map users to
105-
their salted encrypted password
106-
*/
101+
// HtpasswdFile is a File holding basic authentication data.
107102
type HtpasswdFile struct {
103+
// File is used for automatic reloading of the authentication data.
108104
File
105+
// Users is a map of users to their secrets (salted encrypted
106+
// passwords).
109107
Users map[string]string
110108
mu sync.RWMutex
111109
}
112110

113-
func reload_htpasswd(h *HtpasswdFile) {
111+
func reloadHTPasswd(h *HtpasswdFile) {
114112
r, err := os.Open(h.Path)
115113
if err != nil {
116114
panic(err)
117115
}
118-
csv_reader := csv.NewReader(r)
119-
csv_reader.Comma = ':'
120-
csv_reader.Comment = '#'
121-
csv_reader.TrimLeadingSpace = true
116+
reader := csv.NewReader(r)
117+
reader.Comma = ':'
118+
reader.Comment = '#'
119+
reader.TrimLeadingSpace = true
122120

123-
records, err := csv_reader.ReadAll()
121+
records, err := reader.ReadAll()
124122
if err != nil {
125123
panic(err)
126124
}
@@ -133,14 +131,13 @@ func reload_htpasswd(h *HtpasswdFile) {
133131
}
134132
}
135133

136-
/*
137-
SecretProvider implementation based on htpasswd-formated files. Will
138-
reload htpasswd file on changes. Will panic on syntax errors in
139-
htpasswd files. Realm argument of the SecretProvider is ignored.
140-
*/
134+
// HtpasswdFileProvider is a SecretProvider implementation based on
135+
// htpasswd-formated files. It will automatically reload htpasswd file
136+
// on changes. It panics on syntax errors in htpasswd files. Realm
137+
// argument of the SecretProvider is ignored.
141138
func HtpasswdFileProvider(filename string) SecretProvider {
142139
h := &HtpasswdFile{File: File{Path: filename}}
143-
h.Reload = func() { reload_htpasswd(h) }
140+
h.Reload = func() { reloadHTPasswd(h) }
144141
return func(user, realm string) string {
145142
h.ReloadIfNeeded()
146143
h.mu.RLock()

0 commit comments

Comments
 (0)