mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Implement review suggestions
This commit is contained in:
parent
483cbad600
commit
ac0a5176b3
3 changed files with 13 additions and 14 deletions
|
@ -272,7 +272,7 @@ func (e *Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Wait for the owning module to be ready.
|
// Wait for the owning module to be ready.
|
||||||
if !moduleIsReady(e.BelongsTo) {
|
if !moduleIsReady(e.BelongsTo) {
|
||||||
http.Error(w, "The API endpoint is not ready yet. Please try again later.", http.StatusServiceUnavailable)
|
http.Error(w, "The API endpoint is not ready yet or the its module is not enabled. Please try again later.", http.StatusServiceUnavailable)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,23 +24,23 @@ func GetNextBlock(data []byte) ([]byte, int, error) {
|
||||||
// EncodedSize returns the size required to varint-encode an uint.
|
// EncodedSize returns the size required to varint-encode an uint.
|
||||||
func EncodedSize(n uint64) (size int) {
|
func EncodedSize(n uint64) (size int) {
|
||||||
switch {
|
switch {
|
||||||
case n < 128:
|
case n < 1<<7: // < 128
|
||||||
return 1
|
return 1
|
||||||
case n < 16384:
|
case n < 1<<14: // < 16384
|
||||||
return 2
|
return 2
|
||||||
case n < 2097152:
|
case n < 1<<21: // < 2097152
|
||||||
return 3
|
return 3
|
||||||
case n < 268435456:
|
case n < 1<<28: // < 268435456
|
||||||
return 4
|
return 4
|
||||||
case n < 34359738368:
|
case n < 1<<35: // < 34359738368
|
||||||
return 5
|
return 5
|
||||||
case n < 4398046511104:
|
case n < 1<<42: // < 4398046511104
|
||||||
return 6
|
return 6
|
||||||
case n < 562949953421312:
|
case n < 1<<49: // < 562949953421312
|
||||||
return 7
|
return 7
|
||||||
case n < 72057594037927936:
|
case n < 1<<56: // < 72057594037927936
|
||||||
return 8
|
return 8
|
||||||
case n < 9223372036854775808:
|
case n < 1<<63: // < 9223372036854775808
|
||||||
return 9
|
return 9
|
||||||
default:
|
default:
|
||||||
return 10
|
return 10
|
||||||
|
|
|
@ -224,10 +224,11 @@ func (m *Module) checkIfStopComplete() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Module) stop(reports chan *report) {
|
func (m *Module) stop(reports chan *report) {
|
||||||
// check and set intermediate status
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
|
||||||
|
// check and set intermediate status
|
||||||
if m.status != StatusOnline {
|
if m.status != StatusOnline {
|
||||||
m.Unlock()
|
|
||||||
go func() {
|
go func() {
|
||||||
reports <- &report{
|
reports <- &report{
|
||||||
module: m,
|
module: m,
|
||||||
|
@ -249,8 +250,6 @@ func (m *Module) stop(reports chan *report) {
|
||||||
m.stopFlag.Set()
|
m.stopFlag.Set()
|
||||||
m.cancelCtx()
|
m.cancelCtx()
|
||||||
|
|
||||||
m.Unlock()
|
|
||||||
|
|
||||||
go m.stopAllTasks(reports, stopComplete)
|
go m.stopAllTasks(reports, stopComplete)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue