setConfigToRequest sets the parameters passed via Config to the Request.
(req *Request, config ...Config)
| 844 | |
| 845 | // setConfigToRequest sets the parameters passed via Config to the Request. |
| 846 | func setConfigToRequest(req *Request, config ...Config) { |
| 847 | if len(config) == 0 { |
| 848 | return |
| 849 | } |
| 850 | cfg := config[0] |
| 851 | |
| 852 | if cfg.Ctx != nil { |
| 853 | req.SetContext(cfg.Ctx) |
| 854 | } |
| 855 | |
| 856 | if cfg.UserAgent != "" { |
| 857 | req.SetUserAgent(cfg.UserAgent) |
| 858 | } |
| 859 | |
| 860 | if cfg.Referer != "" { |
| 861 | req.SetReferer(cfg.Referer) |
| 862 | } |
| 863 | |
| 864 | if cfg.Header != nil { |
| 865 | req.SetHeaders(cfg.Header) |
| 866 | } |
| 867 | |
| 868 | if cfg.Param != nil { |
| 869 | req.SetParams(cfg.Param) |
| 870 | } |
| 871 | |
| 872 | if cfg.Cookie != nil { |
| 873 | req.SetCookies(cfg.Cookie) |
| 874 | } |
| 875 | |
| 876 | if cfg.PathParam != nil { |
| 877 | req.SetPathParams(cfg.PathParam) |
| 878 | } |
| 879 | |
| 880 | if cfg.Timeout != 0 { |
| 881 | req.SetTimeout(cfg.Timeout) |
| 882 | } |
| 883 | |
| 884 | if cfg.MaxRedirects != 0 { |
| 885 | req.SetMaxRedirects(cfg.MaxRedirects) |
| 886 | } |
| 887 | |
| 888 | if cfg.DisablePathNormalizing { |
| 889 | req.SetDisablePathNormalizing(true) |
| 890 | } |
| 891 | |
| 892 | if cfg.Body != nil { |
| 893 | switch v := cfg.Body.(type) { |
| 894 | case []byte: |
| 895 | req.SetRawBody(v) |
| 896 | case string: |
| 897 | req.SetRawBody([]byte(v)) |
| 898 | default: |
| 899 | req.SetJSON(cfg.Body) |
| 900 | } |
| 901 | return |
| 902 | } |
| 903 |