Browse Source

fix option set return self

ls 2 years ago
parent
commit
0e48ece432
1 changed files with 34 additions and 17 deletions
  1. 34 17
      xhttp/option.go

+ 34 - 17
xhttp/option.go

@@ -52,49 +52,58 @@ func DefaultRequestOption() RequestOption {
 }
 
 // SetTimeOut set request timeout
-func (r *RequestOption) SetTimeOut(v time.Duration) {
+func (r *RequestOption) SetTimeOut(v time.Duration) *RequestOption {
 	r.RequestTimeOut = v
+	return r
 }
 
 // SetResponseHeaderTimeout set response header timeout
-func (r *RequestOption) SetResponseHeaderTimeout(v time.Duration) {
+func (r *RequestOption) SetResponseHeaderTimeout(v time.Duration) *RequestOption {
 	r.ResponseHeaderTimeout = v
+	return r
 }
 
 // SetCert set request cert & key file
-func (r *RequestOption) SetCert(certFile, keyFile string) {
+func (r *RequestOption) SetCert(certFile, keyFile string) *RequestOption {
 	r.CertFile = certFile
 	r.KeyFile = keyFile
+	return r
 }
 
 // SetHeader set header
-func (r *RequestOption) SetHeader(k, v string) {
+func (r *RequestOption) SetHeader(k, v string) *RequestOption {
 	r.Headers[k] = v
+	return r
 }
 
 // AcceptEncodingGZIP Accept-Encoding gzip
-func (r *RequestOption) AcceptEncodingGZIP() {
+func (r *RequestOption) AcceptEncodingGZIP() *RequestOption {
 	r.Headers[AcceptEncoding] = "gzip, deflate, br"
+	return r
 }
 
 // SetContentType set Content-Type
-func (r *RequestOption) SetContentType(v string) {
+func (r *RequestOption) SetContentType(v string) *RequestOption {
 	r.Headers[ContentType] = v
+	return r
 }
 
 // SetContentTypeJSON Content-Type json
-func (r *RequestOption) SetContentTypeJSON() {
+func (r *RequestOption) SetContentTypeJSON() *RequestOption {
 	r.Headers[ContentType] = ContentTypeJSON
+	return r
 }
 
 // SetContentTypeJSON Content-Type json
-func (r *RequestOption) SetContentTypeURL() {
+func (r *RequestOption) SetContentTypeURL() *RequestOption {
 	r.Headers[ContentType] = ContentTypeURL
+	return r
 }
 
 // SetContentTypeJSON Content-Type json
-func (r *RequestOption) SetContentTypeXML() {
+func (r *RequestOption) SetContentTypeXML() *RequestOption {
 	r.Headers[ContentType] = ContentTypeXML
+	return r
 }
 
 func DefaultServerOption() ServerOption {
@@ -111,41 +120,49 @@ func DefaultServerOption() ServerOption {
 }
 
 // SetReadTimeout set ReadTimeout
-func (s *ServerOption) SetReadTimeout(t time.Duration) {
+func (s *ServerOption) SetReadTimeout(t time.Duration) *ServerOption {
 	s.ReadTimeout = t
+	return s
 }
 
 // SetReadHeaderTimeout set ReadHeaderTimeout
-func (s *ServerOption) SetReadHeaderTimeout(t time.Duration) {
+func (s *ServerOption) SetReadHeaderTimeout(t time.Duration) *ServerOption {
 	s.ReadHeaderTimeout = t
+	return s
 }
 
 // SetWriteTimeout set WriteTimeout
-func (s *ServerOption) SetWriteTimeout(t time.Duration) {
+func (s *ServerOption) SetWriteTimeout(t time.Duration) *ServerOption {
 	s.WriteTimeout = t
+	return s
 }
 
 // SetIdleTimeout set IdleTimeout
-func (s *ServerOption) SetIdleTimeout(t time.Duration) {
+func (s *ServerOption) SetIdleTimeout(t time.Duration) *ServerOption {
 	s.IdleTimeout = t
+	return s
 }
 
 // SetMaxHeaderBytes set MaxHeaderBytes
-func (s *ServerOption) SetMaxHeaderBytes(n int) {
+func (s *ServerOption) SetMaxHeaderBytes(n int) *ServerOption {
 	s.MaxHeaderBytes = n
+	return s
 }
 
 // SetShutdownTimeout set ShutdownTimeout
-func (s *ServerOption) SetShutdownTimeout(t time.Duration) {
+func (s *ServerOption) SetShutdownTimeout(t time.Duration) *ServerOption {
 	s.ShutdownTimeout = t
+	return s
 }
 
 // SetCertFile set CertFile
-func (s *ServerOption) SetCertFile(path string) {
+func (s *ServerOption) SetCertFile(path string) *ServerOption {
 	s.CertFile = path
+	return s
 }
 
 // SetKeyFile set KeyFile
-func (s *ServerOption) SetKeyFile(path string) {
+func (s *ServerOption) SetKeyFile(path string) *ServerOption {
 	s.KeyFile = path
+	return s
 }