initial http support
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -22,6 +22,7 @@ type Check struct {
|
||||
Tasks []*Task `json:"tasks,omitempty" yaml:"tasks,omitempty"`
|
||||
Timeout mtime.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
|
||||
Interval mtime.Duration `json:"interval,omitempty" yaml:"interval,omitempty"`
|
||||
Active bool `json:"active,omitempty" yaml:"active,omitempty"`
|
||||
}
|
||||
|
||||
type HTTPConfig struct {
|
||||
@@ -52,6 +53,7 @@ type Task struct {
|
||||
TLSVerify *bool `json:"tls_verify,omitempty" yaml:"tls_verify,omitempty"`
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
Timeout mtime.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
|
||||
Active bool `json:"active,omitempty" yaml:"active,omitempty"`
|
||||
}
|
||||
|
||||
func (cfg *Config) Parse(r io.Reader) error {
|
||||
|
@@ -10,7 +10,7 @@ import (
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
func Call(ctx context.Context, l logger.Logger, c client.Client, addr string, td time.Duration, req client.Request, rsp interface{}) error {
|
||||
func Call(ctx context.Context, l logger.Logger, c client.Client, addr string, td time.Duration, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
var err error
|
||||
uid, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
|
30
pkg/httpconn/httpconn.go
Normal file
30
pkg/httpconn/httpconn.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package httpconn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"go.unistack.org/micro/v3/client"
|
||||
"go.unistack.org/micro/v3/logger"
|
||||
)
|
||||
|
||||
func Call(ctx context.Context, l logger.Logger, c client.Client, addr string, td time.Duration, req client.Request, rsp interface{}, opts ...client.CallOption) error {
|
||||
var err error
|
||||
uid, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
l.Error(ctx, "failed to generate x-request-id", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = c.Call(ctx, req, rsp,
|
||||
client.WithAddress(addr),
|
||||
client.WithRequestTimeout(td),
|
||||
// client.WithContentType("application/json"),
|
||||
)
|
||||
if err != nil {
|
||||
l.Error(ctx, "call failed", "x-request-id", uid.String(), err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user