forked from goraz/onion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
so there is a simple way to reload config. need to create a sample for this
- Loading branch information
1 parent
ba095aa
commit 520c6da
Showing
3 changed files
with
169 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package onion | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
) | ||
|
||
var ( | ||
globalLock = &sync.RWMutex{} | ||
) | ||
|
||
// String is the string value holder, with safe lock for concurrent reload | ||
type String interface { | ||
String() string | ||
} | ||
|
||
// Int is the int value holder, with safe lock for concurrent reload | ||
type Int interface { | ||
// Return the int value | ||
Int() int | ||
// Return int64 value | ||
Int64() int64 | ||
// Return duration value | ||
Duration() time.Duration | ||
} | ||
|
||
// Bool is the bool value holder, with safe lock for concurrent reload | ||
type Bool interface { | ||
// The bool value | ||
Bool() bool | ||
} | ||
|
||
// Bool is the bool value holder, with safe lock for concurrent reload | ||
type Float interface { | ||
Float32() float32 | ||
Float64() float64 | ||
} | ||
|
||
type stringHolder struct { | ||
value *string | ||
} | ||
|
||
func (sh stringHolder) String() string { | ||
globalLock.RLock() | ||
defer globalLock.RUnlock() | ||
|
||
return *sh.value | ||
} | ||
|
||
type intHolder struct { | ||
value *int64 | ||
} | ||
|
||
func (ih intHolder) Int() int { | ||
globalLock.RLock() | ||
defer globalLock.RUnlock() | ||
|
||
return int(*ih.value) | ||
} | ||
|
||
func (ih intHolder) Int64() int64 { | ||
globalLock.RLock() | ||
defer globalLock.RUnlock() | ||
|
||
return *ih.value | ||
} | ||
|
||
func (ih intHolder) Duration() time.Duration { | ||
globalLock.RLock() | ||
defer globalLock.RUnlock() | ||
|
||
return time.Duration(*ih.value) | ||
} | ||
|
||
type boolHolder struct { | ||
value *bool | ||
} | ||
|
||
func (bh boolHolder) Bool() bool { | ||
globalLock.RLock() | ||
defer globalLock.RUnlock() | ||
|
||
return *bh.value | ||
} | ||
|
||
type floatHolder struct { | ||
value *float64 | ||
} | ||
|
||
func (fh floatHolder) Float32() float32 { | ||
globalLock.RLock() | ||
defer globalLock.RUnlock() | ||
|
||
return float32(*fh.value) | ||
} | ||
|
||
func (fh floatHolder) Float64() float64 { | ||
globalLock.RLock() | ||
defer globalLock.RUnlock() | ||
|
||
return *fh.value | ||
} |