]> 127.0.0.1 Git - part/.git/commitdiff
51
authorqydysky <qydysky@foxmail.com>
Sun, 16 Aug 2020 08:00:39 +0000 (16:00 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 16 Aug 2020 08:00:39 +0000 (16:00 +0800)
Limit.go
Log.go

index ae46d1ecec237e9fef610e41e6658e7c78a8577d..80957b7e79a8f762eb074e34d4c826f555f7d980 100644 (file)
--- a/Limit.go
+++ b/Limit.go
@@ -14,14 +14,27 @@ type Limitl struct {
 
 func Limit(Max,Second,TimeOut int) (*Limitl) {
 
-       returnVal := Limitl{}
-       if Max < 1 || Second < 1 || TimeOut < Second{return &returnVal}
+       // Logf().NoShow(false)
 
-       returnVal = Limitl{
+       if Max < 1 {
+               Logf().E("Limit:Max < 1 is true.Set to 1")
+               Max = 1
+       }
+
+       returnVal := Limitl{
                Max:Max,
+               Channl:make(chan bool,Max),
+       }
+
+       if Second < 1 || TimeOut < Second{
+               Logf().E("Limit:Second < 1 || TimeOut < Second is true.Set Stop to true")
+               returnVal.Stop = true
+               return &returnVal
+       }
+
+       returnVal = Limitl{
                Second:Second,
                TimeOut:TimeOut,
-               Channl:make(chan bool,Max),
        }
 
        go func(returnVal *Limitl){
diff --git a/Log.go b/Log.go
index 1b6c1e53293492e61e7628aa85b5e6e278598d34..0818ed70bc9403bba5d5e3703901e0026e4a4fa6 100644 (file)
--- a/Log.go
+++ b/Log.go
@@ -9,6 +9,7 @@ import (
 
 type logl struct {
     fileName string
+    noShow bool
     channelN chan int
     channel chan interface{}
     wantLog chan bool
@@ -84,6 +85,7 @@ func (l *logl) New(fileP string) {
         
             for len(l.channelN) != 0 {
                 i := <- l.channelN
+                if l.noShow {continue}
                 switch i {
                 case -1:
                     l.Close()
@@ -106,6 +108,10 @@ func (l *logl) New(fileP string) {
     }()
 }
 
+func (l *logl) NoShow(NoShow bool){
+    l.noShow = NoShow
+}
+
 func (l *logl) Close(){
     l.fileName = ""
 }
@@ -117,24 +123,28 @@ func (l *logl) WClose(){
 }
 
 func (l *logl) T(i ...interface{}){
+    if l.noShow {return}
     if l.fileName == "" {log.Println("TRACE:", i);return}
     l.channelN <- 0
     l.channel <- i
     if len(l.wantLog) ==0 {l.wantLog <- true;l.wantLog <- true}
 }
 func (l *logl) I(i ...interface{}){
+    if l.noShow {return}
     if l.fileName == "" {log.Println("INFO:", i);return}
     l.channelN <- 1
     l.channel <- i
     if len(l.wantLog) ==0 {l.wantLog <- true;l.wantLog <- true}
 }
 func (l *logl) W(i ...interface{}){
+    if l.noShow {return}
     if l.fileName == "" {log.Println("WARNING:", i);return}
     l.channelN <- 2
     l.channel <- i
     if len(l.wantLog) ==0 {l.wantLog <- true;l.wantLog <- true}
 }
 func (l *logl) E(i ...interface{}){
+    if l.noShow {return}
     if l.fileName == "" {log.Println("ERROR:", i);return}
     l.channelN <- 3
     l.channel <- i