Skip to content

Commit e014898

Browse files
Bump the sunshine group in /service with 2 updates (#169)
* Bump the sunshine group in /service with 2 updates Bumps the sunshine group in /service with 2 updates: [github.com/sunshineplan/service](https://github.com/sunshineplan/service) and [github.com/sunshineplan/utils](https://github.com/sunshineplan/utils). Updates `github.com/sunshineplan/service` from 1.0.22 to 1.0.24 - [Release notes](https://github.com/sunshineplan/service/releases) - [Commits](sunshineplan/service@v1.0.22...v1.0.24) Updates `github.com/sunshineplan/utils` from 0.1.80 to 0.1.82 - [Release notes](https://github.com/sunshineplan/utils/releases) - [Commits](sunshineplan/utils@v0.1.80...v0.1.82) --- updated-dependencies: - dependency-name: github.com/sunshineplan/service dependency-version: 1.0.24 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: sunshine - dependency-name: github.com/sunshineplan/utils dependency-version: 0.1.82 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: sunshine ... Signed-off-by: dependabot[bot] <support@github.com> * Update --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: sunshineplan <sunshineplan@users.noreply.github.com>
1 parent 0add153 commit e014898

6 files changed

Lines changed: 39 additions & 31 deletions

File tree

service/autoproxy.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,20 @@ func addPerHost(p *proxy.PerHost, s string, custom bool) *proxy.PerHost {
106106
if custom {
107107
p.AddFromString(s)
108108
} else {
109-
for _, i := range txt.ReadAll(strings.NewReader(s)) {
110-
if strings.HasSuffix(i, "@cn") {
111-
continue
112-
}
113-
i = strings.ReplaceAll(i, ":@ads", "")
114-
switch {
115-
case strings.HasPrefix(i, "domain:"):
116-
p.AddZone(strings.TrimPrefix(i, "domain:"))
117-
case strings.HasPrefix(i, "full:"):
118-
p.AddHost(strings.TrimPrefix(i, "full:"))
109+
if res, err := txt.ReadAll(strings.NewReader(s)); err != nil {
110+
errorLogger.Print(err)
111+
} else {
112+
for _, i := range res {
113+
if strings.HasSuffix(i, "@cn") {
114+
continue
115+
}
116+
i = strings.ReplaceAll(i, ":@ads", "")
117+
switch {
118+
case strings.HasPrefix(i, "domain:"):
119+
p.AddZone(strings.TrimPrefix(i, "domain:"))
120+
case strings.HasPrefix(i, "full:"):
121+
p.AddHost(strings.TrimPrefix(i, "full:"))
122+
}
119123
}
120124
}
121125
}

service/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ require (
66
github.com/fsnotify/fsnotify v1.9.0
77
github.com/sunshineplan/httpproxy v0.0.0-00010101000000-000000000000
88
github.com/sunshineplan/limiter v1.0.0
9-
github.com/sunshineplan/service v1.0.22
10-
github.com/sunshineplan/utils v0.1.80
9+
github.com/sunshineplan/service v1.0.24
10+
github.com/sunshineplan/utils v0.1.82
1111
golang.org/x/net v0.46.0
1212
golang.org/x/time v0.14.0
1313
)

service/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S
22
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
33
github.com/sunshineplan/limiter v1.0.0 h1:wx3q5eS5J+ggXlAxzg9k6UbDyJYrysNmHyxt5cNmCP8=
44
github.com/sunshineplan/limiter v1.0.0/go.mod h1:+Pjd5Pu7i5YclrnFz+MBFxGB9+MZ2cytQeV+S9kXOxY=
5-
github.com/sunshineplan/service v1.0.22 h1:MFXKIbcd3POiJb9KRI8oeybc2qN0p79vv9f+OL88EDU=
6-
github.com/sunshineplan/service v1.0.22/go.mod h1:JR7cTSNJVlajjXfXobA3Rr46z88M+6VK6coxq7JmyrY=
7-
github.com/sunshineplan/utils v0.1.80 h1:dVGZqO3HvwxqyDwuRLwCm2QMZp7Wx2//F15PnD4wOt4=
8-
github.com/sunshineplan/utils v0.1.80/go.mod h1:R7MInPRKnExzzNGJ9qY1W0+11P/3jc6IO5ICuGDPA1w=
5+
github.com/sunshineplan/service v1.0.24 h1:Ma+75ZUUmMjucWg98aJIJFntLgo0TNsVPeWUuZYIOMo=
6+
github.com/sunshineplan/service v1.0.24/go.mod h1:XJwWAFNd4gEYHl47KgG2zhm2Y8e5RN/En0vIpqd7C4U=
7+
github.com/sunshineplan/utils v0.1.82 h1:GmRfNLxhsKfkroRHZHTdxNE9GcF77t5+A2rLOZnwtmM=
8+
github.com/sunshineplan/utils v0.1.82/go.mod h1:R7MInPRKnExzzNGJ9qY1W0+11P/3jc6IO5ICuGDPA1w=
99
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
1010
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
1111
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=

service/limit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func (limit limit) isExceeded(record *record) bool {
6767
if limit.daily == 0 && limit.monthly == 0 {
6868
return false
6969
}
70-
if limit.daily == 0 || record.today.Load() < int64(limit.daily) {
71-
return record.monthly.Load() >= int64(limit.monthly)
70+
if limit.daily == 0 || record.today.Get() < int64(limit.daily) {
71+
return record.monthly.Get() >= int64(limit.monthly)
7272
}
73-
return record.today.Load() >= int64(limit.daily)
73+
return record.today.Get() >= int64(limit.daily)
7474
}

service/record.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func checkDayChange() {
2828
t := time.Now()
2929
if now.YearDay() != t.YearDay() {
3030
recordMap.Range(func(_ user, v *record) bool {
31-
v.today.Add(-v.today.Load())
31+
v.today.Add(-v.today.Get())
3232
if t.Day() == 1 {
33-
v.monthly.Add(-v.monthly.Load())
33+
v.monthly.Add(-v.monthly.Get())
3434
}
3535
return true
3636
})
@@ -43,7 +43,7 @@ type record struct {
4343
}
4444

4545
func (r *record) writer(w io.Writer) io.Writer {
46-
return r.today.AddWriter(r.monthly.AddWriter(r.total.AddWriter(w)))
46+
return counter.CountWriter(counter.CountWriter(counter.CountWriter(w, &r.total), &r.monthly), &r.today)
4747
}
4848

4949
func store(user user, today, monthly, total int64) *record {
@@ -90,7 +90,7 @@ func parseRecord(rows []string) {
9090
continue
9191
}
9292
}
93-
if t == now {
93+
if t.Equal(now) {
9494
today, err = strconv.ParseInt(s[1], 10, 64)
9595
if err != nil {
9696
errorLogger.Println(row, err)
@@ -116,13 +116,13 @@ func saveRecord(base *Base) {
116116

117117
base.accounts.Range(func(a auth.Basic, _ *limit) bool {
118118
if v, ok := recordMap.Load(user{a.Username, false}); ok {
119-
fmt.Fprintf(zw, "%s:%d:%d:%d\n", a.Username, v.today.Load(), v.monthly.Load(), v.total.Load())
119+
fmt.Fprintf(zw, "%s:%d:%d:%d\n", a.Username, v.today.Get(), v.monthly.Get(), v.total.Get())
120120
}
121121
return true
122122
})
123123
base.whitelist.Range(func(a allow, _ *limit) bool {
124124
if v, ok := recordMap.Load(user{string(a), true}); ok {
125-
fmt.Fprintf(zw, "%s[w]:%d:%d:%d\n", a, v.today.Load(), v.monthly.Load(), v.total.Load())
125+
fmt.Fprintf(zw, "%s[w]:%d:%d:%d\n", a, v.today.Get(), v.monthly.Get(), v.total.Get())
126126
}
127127
return true
128128
})
@@ -138,7 +138,11 @@ func initRecord(base *Base) {
138138
defer f.Close()
139139
if zr, err := gzip.NewReader(f); err == nil {
140140
defer zr.Close()
141-
parseRecord(txt.ReadAll(zr))
141+
if rows, err := txt.ReadAll(zr); err == nil {
142+
parseRecord(rows)
143+
} else {
144+
errorLogger.Print(err)
145+
}
142146
} else {
143147
errorLogger.Print(err)
144148
}

service/status.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ func getUsage(user user) *usage {
3838
if v, ok := recordMap.Load(user); ok {
3939
res := usagePool.Get()
4040
res.user = user
41-
res.today = unit.ByteSize(v.today.Load())
42-
res.monthly = unit.ByteSize(v.monthly.Load())
43-
res.total = unit.ByteSize(v.total.Load())
41+
res.today = unit.ByteSize(v.today.Get())
42+
res.monthly = unit.ByteSize(v.monthly.Get())
43+
res.total = unit.ByteSize(v.total.Get())
4444
return res
4545
}
4646
return nil
@@ -119,8 +119,8 @@ func saveStatus(base *Base, servers []*httpsvr.Server) {
119119
fmt.Fprintln(f, "Throughput:")
120120
var send, receive int64
121121
for _, i := range servers {
122-
send += i.WriteCount()
123-
receive += i.ReadCount()
122+
send += i.WriteBytes()
123+
receive += i.WriteBytes()
124124
}
125125
fmt.Fprintf(f, "Send: %s Receive: %s\n", unit.ByteSize(send), unit.ByteSize(receive))
126126
fmt.Fprintln(f)

0 commit comments

Comments
 (0)