mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
fixed: make log api unblocked
This commit is contained in:
parent
3d0048425b
commit
c4d41345df
|
@ -159,9 +159,19 @@ func (d *Decoder) decodeSlice(name string, data any, val reflect.Value) error {
|
|||
for valSlice.Len() <= i {
|
||||
valSlice = reflect.Append(valSlice, reflect.Zero(valElemType))
|
||||
}
|
||||
currentField := valSlice.Index(i)
|
||||
|
||||
fieldName := fmt.Sprintf("%s[%d]", name, i)
|
||||
if currentData == nil {
|
||||
// in weakly type mode, null will convert to zero value
|
||||
if d.option.WeaklyTypedInput {
|
||||
continue
|
||||
}
|
||||
// in non-weakly type mode, null will convert to nil if element's zero value is nil, otherwise return an error
|
||||
if elemKind := valElemType.Kind(); elemKind == reflect.Map || elemKind == reflect.Slice {
|
||||
continue
|
||||
}
|
||||
return fmt.Errorf("'%s' can not be null", fieldName)
|
||||
}
|
||||
currentField := valSlice.Index(i)
|
||||
if err := d.decode(fieldName, currentData, currentField); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
20
log/log.go
20
log/log.go
|
@ -10,8 +10,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
logCh = make(chan *Event)
|
||||
source = observable.NewObservable[*Event](logCh)
|
||||
logCh = make(chan Event)
|
||||
source = observable.NewObservable[Event](logCh)
|
||||
level = INFO
|
||||
)
|
||||
|
||||
|
@ -57,12 +57,12 @@ func Fatalln(format string, v ...any) {
|
|||
log.Fatalf(format, v...)
|
||||
}
|
||||
|
||||
func Subscribe() observable.Subscription[*Event] {
|
||||
func Subscribe() observable.Subscription[Event] {
|
||||
sub, _ := source.Subscribe()
|
||||
return sub
|
||||
}
|
||||
|
||||
func UnSubscribe(sub observable.Subscription[*Event]) {
|
||||
func UnSubscribe(sub observable.Subscription[Event]) {
|
||||
source.UnSubscribe(sub)
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ func SetLevel(newLevel LogLevel) {
|
|||
level = newLevel
|
||||
}
|
||||
|
||||
func print(data *Event) {
|
||||
func print(data Event) {
|
||||
if data.LogLevel < level {
|
||||
return
|
||||
}
|
||||
|
@ -91,15 +91,9 @@ func print(data *Event) {
|
|||
}
|
||||
}
|
||||
|
||||
func newLog(logLevel LogLevel, format string, v ...any) *Event {
|
||||
return &Event{
|
||||
func newLog(logLevel LogLevel, format string, v ...any) Event {
|
||||
return Event{
|
||||
LogLevel: logLevel,
|
||||
Payload: fmt.Sprintf(format, v...),
|
||||
}
|
||||
}
|
||||
|
||||
func PrintLog(logLevel LogLevel, format string, v ...interface{}) {
|
||||
event := newLog(logLevel, format, v...)
|
||||
logCh <- event
|
||||
print(event)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user