mirror of
https://github.com/mentos1386/zdravko.git
synced 2024-11-26 09:17:55 +00:00
40 lines
712 B
Go
40 lines
712 B
Go
|
package activities
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type HealtcheckHttpActivityParam struct {
|
||
|
Url string
|
||
|
Method string
|
||
|
}
|
||
|
|
||
|
type HealthcheckHttpActivityResult struct {
|
||
|
Success bool
|
||
|
}
|
||
|
|
||
|
func HealthcheckHttpActivityDefinition(ctx context.Context, param HealtcheckHttpActivityParam) (*HealthcheckHttpActivityResult, 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
|
||
|
}
|
||
|
|
||
|
return &HealthcheckHttpActivityResult{Success: response.StatusCode == 200}, nil
|
||
|
}
|