-
Notifications
You must be signed in to change notification settings - Fork 470
/
client.go
executable file
·42 lines (36 loc) · 1.38 KB
/
client.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
// Package client is an interface for any protocol's client
package client
import (
"context"
"errors"
"github.com/go-chassis/go-chassis/v2/core/invocation"
)
// ErrCanceled means Request is canceled by context management
var ErrCanceled = errors.New("request cancelled")
// TransportFailure is caused by client call failure
// for example: resp, err = client.Do(req)
// if err is not nil then should wrap original error with TransportFailure
type TransportFailure struct {
Message string
}
// Error return error message
func (e TransportFailure) Error() string {
return e.Message
}
// ProtocolClient is a interface to communicate with one kind of ProtocolServer, it is used in transport handler.
// this handler orchestrate client implementation.
// gRPC protocol client, http protocol client, or you can implement your own.
type ProtocolClient interface {
// TODO use invocation.Response as rsp
// Call is the key function you must implement
Call(ctx context.Context, addr string, inv *invocation.Invocation, rsp interface{}) error
// if your protocol has response status(such as http return 200, 500 status code),
// you need to return it according to response
Status(rsp interface{}) (status int, err error)
String() string
Close() error
// if you want to reload client settings on-fly, such as timeout, TLS config,
// you need to implement it
ReloadConfigs(Options)
GetOptions() Options
}