Skip to content

Commit 500128c

Browse files
committed
refactor(param): use regular type for user info
1 parent a76672d commit 500128c

File tree

5 files changed

+32
-36
lines changed

5 files changed

+32
-36
lines changed

src/param/cli.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,17 +375,17 @@ func ParseCli() (params []*Param, printVersion, printHelp bool, errs []error) {
375375

376376
// users
377377
arrUsersPlain, _ := result.GetStrings("users")
378-
param.UsersPlain = EntriesToUsers(arrUsersPlain)
378+
param.UsersPlain = entriesToUsers(arrUsersPlain)
379379
arrUsersBase64, _ := result.GetStrings("usersbase64")
380-
param.UsersBase64 = EntriesToUsers(arrUsersBase64)
380+
param.UsersBase64 = entriesToUsers(arrUsersBase64)
381381
arrUsersMd5, _ := result.GetStrings("usersmd5")
382-
param.UsersMd5 = EntriesToUsers(arrUsersMd5)
382+
param.UsersMd5 = entriesToUsers(arrUsersMd5)
383383
arrUsersSha1, _ := result.GetStrings("userssha1")
384-
param.UsersSha1 = EntriesToUsers(arrUsersSha1)
384+
param.UsersSha1 = entriesToUsers(arrUsersSha1)
385385
arrUsersSha256, _ := result.GetStrings("userssha256")
386-
param.UsersSha256 = EntriesToUsers(arrUsersSha256)
386+
param.UsersSha256 = entriesToUsers(arrUsersSha256)
387387
arrUsersSha512, _ := result.GetStrings("userssha512")
388-
param.UsersSha512 = EntriesToUsers(arrUsersSha512)
388+
param.UsersSha512 = entriesToUsers(arrUsersSha512)
389389

390390
// listen
391391
listens, _ := result.GetStrings("listens")

src/param/main.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import (
77
"os"
88
)
99

10-
type user struct {
11-
Username string
12-
Password string
13-
}
14-
1510
type Param struct {
1611
Root string
1712
EmptyRoot bool
@@ -52,15 +47,16 @@ type Param struct {
5247
CorsUrls []string
5348
CorsDirs []string
5449

55-
GlobalAuth bool
56-
AuthUrls []string
57-
AuthDirs []string
58-
UsersPlain []*user
59-
UsersBase64 []*user
60-
UsersMd5 []*user
61-
UsersSha1 []*user
62-
UsersSha256 []*user
63-
UsersSha512 []*user
50+
GlobalAuth bool
51+
AuthUrls []string
52+
AuthDirs []string
53+
// value: [username, password]
54+
UsersPlain [][2]string
55+
UsersBase64 [][2]string
56+
UsersMd5 [][2]string
57+
UsersSha1 [][2]string
58+
UsersSha256 [][2]string
59+
UsersSha512 [][2]string
6460
UserMatchCase bool
6561

6662
Certificates []tls.Certificate

src/param/objUtil.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ func loadCertificates(certFiles, keyFiles []string) ([]tls.Certificate, []error)
1010
return goVirtualHost.LoadCertificates(certFiles, keyFiles)
1111
}
1212

13-
func EntriesToUsers(entries []string) []*user {
14-
users := make([]*user, 0, len(entries))
13+
func entriesToUsers(entries []string) [][2]string {
14+
users := make([][2]string, 0, len(entries))
1515
for _, userEntry := range entries {
1616
username := userEntry
1717
password := ""
@@ -22,7 +22,7 @@ func EntriesToUsers(entries []string) []*user {
2222
password = userEntry[colonIndex+1:]
2323
}
2424

25-
users = append(users, &user{username, password})
25+
users = append(users, [2]string{username, password})
2626
}
2727
return users
2828
}

src/param/objUtil_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ func TestEntriesToUsers(t *testing.T) {
88
"user2:",
99
"user3:pass3",
1010
}
11-
users := EntriesToUsers(entries)
11+
users := entriesToUsers(entries)
1212
if len(users) != 3 {
1313
t.Fatal("user count is not 3")
1414
}
15-
if users[0].Username != "" {
15+
if users[0][0] != "" {
1616
t.Fail()
1717
}
18-
if users[0].Password != "pass1" {
18+
if users[0][1] != "pass1" {
1919
t.Fail()
2020
}
21-
if users[1].Username != "user2" {
21+
if users[1][0] != "user2" {
2222
t.Fail()
2323
}
24-
if users[1].Password != "" {
24+
if users[1][1] != "" {
2525
t.Fail()
2626
}
27-
if users[2].Username != "user3" {
27+
if users[2][0] != "user3" {
2828
t.Fail()
2929
}
30-
if users[2].Password != "pass3" {
30+
if users[2][1] != "pass3" {
3131
t.Fail()
3232
}
3333
}

src/serverHandler/vhostHandler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ func NewVhostHandler(
1818
// users
1919
users := user.NewList(p.UserMatchCase)
2020
for _, u := range p.UsersPlain {
21-
errs = serverError.AppendError(errs, users.AddPlain(u.Username, u.Password))
21+
errs = serverError.AppendError(errs, users.AddPlain(u[0], u[1]))
2222
}
2323
for _, u := range p.UsersBase64 {
24-
errs = serverError.AppendError(errs, users.AddBase64(u.Username, u.Password))
24+
errs = serverError.AppendError(errs, users.AddBase64(u[0], u[1]))
2525
}
2626
for _, u := range p.UsersMd5 {
27-
errs = serverError.AppendError(errs, users.AddMd5(u.Username, u.Password))
27+
errs = serverError.AppendError(errs, users.AddMd5(u[0], u[1]))
2828
}
2929
for _, u := range p.UsersSha1 {
30-
errs = serverError.AppendError(errs, users.AddSha1(u.Username, u.Password))
30+
errs = serverError.AppendError(errs, users.AddSha1(u[0], u[1]))
3131
}
3232
for _, u := range p.UsersSha256 {
33-
errs = serverError.AppendError(errs, users.AddSha256(u.Username, u.Password))
33+
errs = serverError.AppendError(errs, users.AddSha256(u[0], u[1]))
3434
}
3535
for _, u := range p.UsersSha512 {
36-
errs = serverError.AppendError(errs, users.AddSha512(u.Username, u.Password))
36+
errs = serverError.AppendError(errs, users.AddSha512(u[0], u[1]))
3737
}
3838

3939
shows, err := wildcardToRegexp(p.Shows)

0 commit comments

Comments
 (0)