fixed: make log api unblocked

This commit is contained in:
gVisor bot 2022-05-06 11:43:53 +08:00
parent 3d0048425b
commit c4d41345df
2 changed files with 19 additions and 15 deletions

View file

@ -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
}

View file

@ -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)
}