Selaa lähdekoodia

fail fast when rolling window size is zero

kevin 4 vuotta sitten
vanhempi
sitoutus
c824e9e118

+ 4 - 0
core/collection/rollingwindow.go

@@ -22,6 +22,10 @@ type (
 )
 
 func NewRollingWindow(size int, interval time.Duration, opts ...RollingWindowOption) *RollingWindow {
+	if size < 1 {
+		panic("size must be greater than 0")
+	}
+
 	w := &RollingWindow{
 		size:     size,
 		win:      newWindow(size),

+ 7 - 0
core/collection/rollingwindow_test.go

@@ -11,6 +11,13 @@ import (
 
 const duration = time.Millisecond * 50
 
+func TestNewRollingWindow(t *testing.T) {
+	assert.NotNil(t, NewRollingWindow(10, time.Second))
+	assert.Panics(t, func() {
+		NewRollingWindow(0, time.Second)
+	})
+}
+
 func TestRollingWindowAdd(t *testing.T) {
 	const size = 3
 	r := NewRollingWindow(size, duration)

+ 0 - 21
tools/goctl/api/main.go

@@ -1,21 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"os"
-
-	"github.com/tal-tech/go-zero/core/logx"
-	"github.com/tal-tech/go-zero/tools/goctl/api/parser"
-)
-
-func main() {
-	if len(os.Args) <= 1 {
-		return
-	}
-
-	p, err := parser.NewParser(os.Args[1])
-	logx.Must(err)
-	api, err := p.Parse()
-	logx.Must(err)
-	fmt.Println(api)
-}