]> 127.0.0.1 Git - part/.git/commitdiff
GetStruct
authorqydysky <qydysky@foxmail.com>
Mon, 12 Apr 2021 07:14:09 +0000 (15:14 +0800)
committerqydysky <qydysky@foxmail.com>
Mon, 12 Apr 2021 07:14:09 +0000 (15:14 +0800)
limit/Limit.go
limit/Limit_test.go

index 92edfc48044208876c7560b2691e676ef35b9cb4..bacfbe5da384fc543e5cf2b60307d309683aa6ce 100644 (file)
@@ -40,4 +40,10 @@ func (l *limit) TO() bool {
                case <-time.After(time.Duration(l.ms_to_timeout)*time.Millisecond):return true;
        }
        return false
+}
+
+//assert interface{} to *limit
+func GetStruct(i interface{}) (l *limit,ok bool) {
+       l,ok = i.(*limit)
+       return 
 }
\ No newline at end of file
index be2730f7f88f490f85059bc534112b466bf16e72..908590e655763a8a1dfa8194ffc5bad0582dfbe0 100644 (file)
@@ -51,4 +51,11 @@ func Test_4(t *testing.T){
                time.Sleep(time.Millisecond)
        }
        t.Log(pass)
+}
+
+func Test_5(t *testing.T){
+       l := New(0,0,10)
+       if v,ok := GetStruct(interface{}(l));!ok{
+               t.Log(`error struct`,v)
+       }
 }
\ No newline at end of file