-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
57 lines (48 loc) · 1.21 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
//
// ______ _ _ _ __ _ _ ____ ___
// | ____| | | | | | |/ _| | | | | |___ \ / _ \
// | |__ __ _| |_| |__ __ _| | |_ __ _| |_| |__ __) | | | |
// | __/ _` | __| '_ \ / _` | | _/ _` | __| '_ \ |__ <| | | |
// | | | (_| | |_| | | | (_| | | || (_| | |_| | | |___) | |_| |
// |_| \__,_|\__|_| |_|\__,_|_|_| \__,_|\__|_| |_|____/ \___/
//
// Written by Fathalfath30.
// Email : fathalfath30@gmail.com
// Follow me on:
// Github : https://github.com/fathalfath30
// Gitlab : https://gitlab.com/Fathalfath30
//
*/
package goquest
import (
"github.com/fathalfath30/goquest/exception"
"net/http"
"net/url"
)
func New(baseUrl string, cfg *Config) (IGoQuest, error) {
gq := new(GoQuest)
u, err := url.Parse(baseUrl)
if err != nil {
return nil, exception.NewGeneralException("failed to parse base url: " + err.Error())
}
gq.BaseUrl = u
if cfg != nil {
// input custom transport
if cfg.Transport != nil {
gq.transport = cfg.Transport
}
// input custom header
if cfg.Header != nil {
gq.header = cfg.Header
}
// put user defined
if cfg.Client != nil {
gq.client = cfg.Client
}
}
if gq.client == nil {
gq.client = &http.Client{}
}
return gq, nil
}