expose http.Client

This commit is contained in:
yzqzss 2024-06-08 01:19:08 +08:00
parent d82eadbc8e
commit 990bea9fd7
3 changed files with 9 additions and 9 deletions

View File

@ -60,8 +60,8 @@ type Tracker struct {
client_version string
project_id string
archivist string
http_client *http.Client
ping_client *http.Client
HTTP_client *http.Client
PING_client *http.Client
_claim_wait_lock sync.Mutex
@ -113,7 +113,7 @@ func (t *Tracker) SelectBestTracker() *Tracker {
for _, node := range TRACKER_NODES {
go func(ctx context.Context, node string) {
elapsed, resp, err := GetPing(ctx, t.ping_client, node)
elapsed, resp, err := GetPing(ctx, t.PING_client, node)
if err != nil {
if ctx.Err() == context.Canceled {
return
@ -169,11 +169,11 @@ func (t *Tracker) StartSelectTrackerBackground() *Tracker {
func GetTracker(project_id string, client_version string, archivist string) *Tracker {
t := &Tracker{
API_VERSION: "v1",
ping_client: &http.Client{
PING_client: &http.Client{
Timeout: 10 * time.Second,
},
project_id: project_id,
http_client: &http.Client{
HTTP_client: &http.Client{
Timeout: 120 * time.Second,
},
client_version: client_version,

View File

@ -48,7 +48,7 @@ func (t *Tracker) FetchProject(timeout time.Duration) (proj *Project, err error)
log.Print(err)
return nil, err
}
r, err := t.http_client.Do(req)
r, err := t.HTTP_client.Do(req)
if err != nil {
log.Print(err)
return nil, err

View File

@ -57,7 +57,7 @@ func (t *Tracker) ClaimTask(with_delay bool) *Task {
time.Sleep(time.Duration(t.Project().Client.ClaimTaskDelay) * time.Second)
t._claim_wait_lock.Unlock()
}
resp, err := t.http_client.Post(t.API_BASE+t.API_VERSION+"/project/"+t.project_id+"/"+t.client_version+"/"+t.archivist+"/claim_task", "", nil)
resp, err := t.HTTP_client.Post(t.API_BASE+t.API_VERSION+"/project/"+t.project_id+"/"+t.client_version+"/"+t.archivist+"/claim_task", "", nil)
if err != nil {
panic(err)
}
@ -107,7 +107,7 @@ func (t *Tracker) UpdateTask(task_id string, id_type string, to_status Status) s
panic("invalid status")
}
resp, err := t.http_client.Post(t.API_BASE+t.API_VERSION+"/project/"+t.project_id+"/"+t.client_version+"/"+t.archivist+"/update_task/"+task_id, "application/x-www-form-urlencoded", strings.NewReader(postData.Encode()))
resp, err := t.HTTP_client.Post(t.API_BASE+t.API_VERSION+"/project/"+t.project_id+"/"+t.client_version+"/"+t.archivist+"/update_task/"+task_id, "application/x-www-form-urlencoded", strings.NewReader(postData.Encode()))
if err != nil {
panic(err)
}
@ -209,7 +209,7 @@ func (t *Tracker) InsertItem(task Task, item_status string, status_type string,
fmt.Println(req.Header)
resp, err := t.http_client.Do(req)
resp, err := t.HTTP_client.Do(req)
if err != nil {
panic(err)
}