Simplify Config Enum Label Too Long

This commit is contained in:
huangsimin 2018-11-08 14:26:51 +08:00
parent 4f88f69899
commit f490fa9c04
2 changed files with 25 additions and 25 deletions

View File

@ -67,26 +67,26 @@ type TypeConfig int
const (
_ TypeConfig = iota
// ConfigRequestTimeout request 包括 dial request redirect 总时间超时
ConfigRequestTimeout // 支持time.Duration 和 int(秒为单位)
// CRequestTimeout request 包括 dial request redirect 总时间超时
CRequestTimeout // 支持time.Duration 和 int(秒为单位)
// ConfigDialTimeout 一个Connect过程的Timeout
ConfigDialTimeout // 支持time.Duration 和 int(秒为单位)
// CDialTimeout 一个Connect过程的Timeout
CDialTimeout // 支持time.Duration 和 int(秒为单位)
// ConfigProxy 代理链接
ConfigProxy // http, https, socks5
// CProxy 代理链接
CProxy // http, https, socks5
// ConfigInsecure InsecureSkipVerify
ConfigInsecure // true, false
// CInsecure InsecureSkipVerify
CInsecure // true, false
// ConfigBasicAuth 帐号认证
ConfigBasicAuth // user pwd
// CBasicAuth 帐号认证
CBasicAuth // user pwd
// ConfigTLS 帐号认证
ConfigTLS // user pwd
// CTLS 帐号认证
CTLS // user pwd
// ConfigCookiejar 持久化 CookieJar
ConfigCookiejar // true or false ; default = true
// CCookiejar 持久化 CookieJar
CCookiejar // true or false ; default = true
)
// NewSession 创建Session
@ -108,7 +108,7 @@ func NewSession() *Session {
func (ses *Session) SetConfig(typeConfig TypeConfig, values interface{}) {
switch typeConfig {
case ConfigRequestTimeout:
case CRequestTimeout:
switch v := values.(type) {
case time.Duration:
ses.client.Timeout = v
@ -123,9 +123,9 @@ func (ses *Session) SetConfig(typeConfig TypeConfig, values interface{}) {
default:
panic(errors.New("error type " + reflect.TypeOf(v).String()))
}
case ConfigDialTimeout:
case CDialTimeout:
// 没时间实现这些小细节
case ConfigCookiejar:
case CCookiejar:
v := values.(bool)
if v {
if ses.client.Jar == nil {
@ -134,7 +134,7 @@ func (ses *Session) SetConfig(typeConfig TypeConfig, values interface{}) {
} else {
ses.client.Jar = nil
}
case ConfigProxy:
case CProxy:
switch v := values.(type) {
case string:
purl, err := (url.Parse(v))
@ -147,11 +147,11 @@ func (ses *Session) SetConfig(typeConfig TypeConfig, values interface{}) {
case nil:
ses.transport.Proxy = nil
}
case ConfigInsecure:
case CInsecure:
ses.transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: !values.(bool)}
case ConfigTLS:
case CTLS:
ses.transport.TLSClientConfig = values.(*tls.Config)
case ConfigBasicAuth:
case CBasicAuth:
if ses.auth == nil {
ses.auth = &BasicAuth{}
}

View File

@ -285,19 +285,19 @@ func TestSession_SetConfig(t *testing.T) {
}{
{
name: "test timeout",
args: args{typeConfig: ConfigRequestTimeout, values: 0.01},
args: args{typeConfig: CRequestTimeout, values: 0.01},
wantErr: true,
},
{
name: "test not timeout",
args: args{typeConfig: ConfigRequestTimeout, values: 5},
args: args{typeConfig: CRequestTimeout, values: 5},
wantErr: false,
},
{
name: "test proxy",
args: args{typeConfig: ConfigProxy, values: "http://474420502.top:7070"},
args: args{typeConfig: CProxy, values: "http://474420502.top:7070"},
wantErr: false,
},
}
@ -319,7 +319,7 @@ func TestSession_SetConfig(t *testing.T) {
func TestSession_SetConfigInsecure(t *testing.T) {
ses := NewSession()
ses.SetConfig(ConfigInsecure, false)
ses.SetConfig(CInsecure, false)
for _, badSSL := range []string{
"https://self-signed.badssl.com/",