add vendor

This commit is contained in:
deepzz0
2017-02-18 15:23:57 +08:00
parent 4ebbc38cc0
commit 562f4d86c6
1371 changed files with 369552 additions and 2 deletions
+39
View File
@@ -0,0 +1,39 @@
package conf
import (
"fmt"
"runtime"
"syscall"
"qiniupkg.com/x/ctype.v7"
"qiniupkg.com/x/rpc.v7"
)
var version = "7.1.0"
var ACCESS_KEY string
var SECRET_KEY string
// ----------------------------------------------------------
const (
ctypeAppName = ctype.ALPHA | ctype.DIGIT | ctype.UNDERLINE | ctype.SPACE_BAR | ctype.SUB | ctype.DOT
)
// userApp should be [A-Za-z0-9_\ \-\.]*
//
func SetAppName(userApp string) error {
if userApp != "" && !ctype.IsType(ctypeAppName, userApp) {
return syscall.EINVAL
}
rpc.UserAgent = fmt.Sprintf(
"QiniuGo/%s (%s; %s; %s) %s", version, runtime.GOOS, runtime.GOARCH, userApp, runtime.Version())
return nil
}
func init() {
SetAppName("")
}
// ----------------------------------------------------------
+35
View File
@@ -0,0 +1,35 @@
package conf
import (
"strings"
"testing"
"qiniupkg.com/x/rpc.v7"
)
func TestUA(t *testing.T) {
err := SetAppName("")
if err != nil {
t.Fatal("expect no error")
}
err = SetAppName("错误的UA")
if err == nil {
t.Fatal("expect an invalid ua format")
}
err = SetAppName("Test0-_.")
if err != nil {
t.Fatal("expect no error")
}
}
func TestFormat(t *testing.T) {
str := "tesT0.-_"
SetAppName(str)
v := rpc.UserAgent
if !strings.Contains(v, str) {
t.Fatal("should include user")
}
if !strings.HasPrefix(v, "QiniuGo/"+version) {
t.Fatal("invalid format")
}
}