2024-02-16 12:07:29 +00:00
|
|
|
package activities
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-02-16 12:41:18 +00:00
|
|
|
"log"
|
2024-02-16 12:07:29 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2024-02-17 19:19:18 +00:00
|
|
|
type HealtcheckHttpParam struct {
|
2024-02-16 12:07:29 +00:00
|
|
|
Url string
|
|
|
|
Method string
|
|
|
|
}
|
|
|
|
|
2024-02-17 19:19:18 +00:00
|
|
|
type HealthcheckHttpResult struct {
|
2024-02-16 12:41:18 +00:00
|
|
|
StatusCode int
|
2024-02-16 12:07:29 +00:00
|
|
|
}
|
|
|
|
|
2024-02-17 19:19:18 +00:00
|
|
|
func HealthcheckHttp(ctx context.Context, param HealtcheckHttpParam) (*HealthcheckHttpResult, error) {
|
2024-02-16 12:07:29 +00:00
|
|
|
if param.Method == "" {
|
|
|
|
param.Method = "GET"
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
response *http.Response
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
switch param.Method {
|
|
|
|
case "GET":
|
|
|
|
response, err = http.Get(param.Url)
|
|
|
|
case "POST":
|
|
|
|
response, err = http.Post(param.Url, "application/json", nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-02-16 12:41:18 +00:00
|
|
|
log.Printf("HealthcheckHttpActivityDefinition produced statuscode %d for url %s", response.StatusCode, param.Url)
|
|
|
|
|
2024-02-17 19:19:18 +00:00
|
|
|
return &HealthcheckHttpResult{StatusCode: response.StatusCode}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type HealtcheckHttpAddToHistoryParam struct {
|
|
|
|
Id string
|
|
|
|
Success bool
|
|
|
|
StatusCode int
|
|
|
|
}
|
|
|
|
|
|
|
|
type HealthcheckHttpAddToHistoryResult struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func HealthcheckHttpWriteResult(ctx context.Context, param HealtcheckHttpParam) (*HealthcheckHttpResult, error) {
|
|
|
|
if param.Method == "" {
|
|
|
|
param.Method = "GET"
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
response *http.Response
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
switch param.Method {
|
|
|
|
case "GET":
|
|
|
|
response, err = http.Get(param.Url)
|
|
|
|
case "POST":
|
|
|
|
response, err = http.Post(param.Url, "application/json", nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("HealthcheckHttpActivityDefinition produced statuscode %d for url %s", response.StatusCode, param.Url)
|
|
|
|
|
|
|
|
return &HealthcheckHttpResult{StatusCode: response.StatusCode}, nil
|
2024-02-16 12:07:29 +00:00
|
|
|
}
|