Darien Raymond 8 jaren geleden
bovenliggende
commit
693702350d

+ 4 - 6
common/crypto/aes.go

@@ -3,15 +3,15 @@ package crypto
 import (
 	"crypto/aes"
 	"crypto/cipher"
+
+	"v2ray.com/core/common"
 )
 
 // NewAesDecryptionStream creates a new AES encryption stream based on given key and IV.
 // Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
 func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
 	aesBlock, err := aes.NewCipher(key)
-	if err != nil {
-		panic(err)
-	}
+	common.Must(err)
 	return cipher.NewCFBDecrypter(aesBlock, iv)
 }
 
@@ -19,8 +19,6 @@ func NewAesDecryptionStream(key []byte, iv []byte) cipher.Stream {
 // Caller must ensure the length of key and IV is either 16, 24 or 32 bytes.
 func NewAesEncryptionStream(key []byte, iv []byte) cipher.Stream {
 	aesBlock, err := aes.NewCipher(key)
-	if err != nil {
-		panic(err)
-	}
+	common.Must(err)
 	return cipher.NewCFBEncrypter(aesBlock, iv)
 }

+ 2 - 3
common/crypto/chacha20_test.go

@@ -5,15 +5,14 @@ import (
 	"encoding/hex"
 	"testing"
 
+	"v2ray.com/core/common"
 	. "v2ray.com/core/common/crypto"
 	"v2ray.com/core/testing/assert"
 )
 
 func mustDecodeHex(s string) []byte {
 	b, err := hex.DecodeString(s)
-	if err != nil {
-		panic(err)
-	}
+	common.Must(err)
 	return b
 }
 

+ 2 - 3
common/net/ipnet_test.go

@@ -4,15 +4,14 @@ import (
 	"net"
 	"testing"
 
+	"v2ray.com/core/common"
 	. "v2ray.com/core/common/net"
 	"v2ray.com/core/testing/assert"
 )
 
 func parseCIDR(str string) *net.IPNet {
 	_, ipNet, err := net.ParseCIDR(str)
-	if err != nil {
-		panic(err)
-	}
+	common.Must(err)
 	return ipNet
 }
 

+ 2 - 5
testing/scenarios/common.go

@@ -81,17 +81,14 @@ var (
 func genTestBinaryPath() {
 	testBinaryPathGen.Do(func() {
 		var tempDir string
-		err := retry.Timed(5, 100).On(func() error {
+		common.Must(retry.Timed(5, 100).On(func() error {
 			dir, err := ioutil.TempDir("", "v2ray")
 			if err != nil {
 				return err
 			}
 			tempDir = dir
 			return nil
-		})
-		if err != nil {
-			panic(err)
-		}
+		}))
 		file := filepath.Join(tempDir, "v2ray.test")
 		if runtime.GOOS == "windows" {
 			file += ".exe"

+ 4 - 5
tools/genproto/main.go

@@ -11,6 +11,8 @@ import (
 	"path/filepath"
 	"runtime"
 	"strings"
+
+	"v2ray.com/core/common"
 )
 
 var protocMap = map[string]string{
@@ -64,7 +66,7 @@ func main() {
 		}
 	}
 
-	err := filepath.Walk(reporoot, func(path string, info os.FileInfo, err error) error {
+	common.Must(filepath.Walk(reporoot, func(path string, info os.FileInfo, err error) error {
 		if err != nil {
 			fmt.Println(err)
 			return err
@@ -90,8 +92,5 @@ func main() {
 		}
 
 		return nil
-	})
-	if err != nil {
-		panic(err)
-	}
+	}))
 }

+ 2 - 3
tools/geoip/geoip_gen.go

@@ -14,6 +14,7 @@ import (
 	"strings"
 
 	"v2ray.com/core/app/router"
+	"v2ray.com/core/common"
 	"v2ray.com/core/common/errors"
 	"v2ray.com/core/tools/geoip"
 
@@ -26,9 +27,7 @@ const (
 
 func main() {
 	resp, err := http.Get(apnicFile)
-	if err != nil {
-		panic(err)
-	}
+	common.Must(err)
 	if resp.StatusCode != 200 {
 		panic(errors.New("unexpected status ", resp.StatusCode))
 	}