Documentation ¶
Index ¶
- type Client
- func (c *Client) Delete(ctx context.Context, path string) error
- func (c *Client) DeleteServer(ctx context.Context) error
- func (c *Client) Get(ctx context.Context, path string, out interface{}) error
- func (c *Client) GetRegistrationState() string
- func (c *Client) GetRegistrationStatus() RegistrationStatus
- func (c *Client) GetServerByEndpoint(ctx context.Context, in GetServerByEndpointIn) (ServerResponse, error)
- func (c *Client) GetServerByID(ctx context.Context, in GetServerByIDIn) (ServerResponse, error)
- func (c *Client) GetServers(ctx context.Context, in GetServersIn) (GetServersResponse, error)
- func (c *Client) GetWithAuth(ctx context.Context, path, appKey, appSecret string, queries map[string]string, ...) error
- func (c *Client) HandleHealthCheck(w http.ResponseWriter, r *http.Request)
- func (c *Client) HandleServerRegistration(w http.ResponseWriter, r *http.Request)
- func (c *Client) LastHealthCheck() time.Time
- func (c *Client) Pair(ctx context.Context, in PairIn) error
- func (c *Client) Post(ctx context.Context, path string, in interface{}) error
- func (c *Client) PostServer(ctx context.Context, in PostServerIn) error
- func (c *Client) PostSession(ctx context.Context, in PostSessionIn) error
- func (c *Client) Secret() string
- func (c *Client) SendSmokeTestResult(ctx context.Context, results hsmoketest.SmokeTestResults) error
- func (c *Client) ServerID() string
- func (c *Client) SetLastHealthCheck(t time.Time)
- func (c *Client) SetServerData(serverID, secret string)
- func (c *Client) Unpair() error
- func (c *Client) UserAuth(ctx context.Context, in UserAuthIn) (UserAuthResponse, error)
- func (c *Client) VerifyUserAuth(token string) error
- type ClientOpts
- func WithClientID(v string) ClientOpts
- func WithDecoder(v Decoder) ClientOpts
- func WithEncoder(v Encoder) ClientOpts
- func WithHDSEndpoint(v string) ClientOpts
- func WithHagallEndpoint(v string) ClientOpts
- func WithPrivateKey(v *ecdsa.PrivateKey) ClientOpts
- func WithRemoteAddr(v string) ClientOpts
- func WithSecret(v string) ClientOpts
- func WithServerID(v string) ClientOpts
- func WithTransport(v http.RoundTripper) ClientOpts
- type Decoder
- type Encoder
- type GetServerByEndpointIn
- type GetServerByIDIn
- type GetServersIn
- type GetServersResponse
- type GetSessionIn
- type PairIn
- type PostServerIn
- type PostSessionIn
- type RegistrationStatus
- type ServerResponse
- type UserAuthIn
- type UserAuthResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // The Hagall endpoint. HagallEndpoint string // The Hagall Discovery Service endpoint. HDSEndpoint string // The HTTP transport used to communicate with the Hagall Discovery Service. // (optional) Transport http.RoundTripper // The function to encode request bodies. Encode Encoder // The function to decode response bodies. Decode Decoder // Setting RemoteAddr to insert a http header x-real-ip=RemoteAddr to request, // allows override of client IP address which read from req.RemoteAddr by default RemoteAddr string // contains filtered or unexported fields }
Client represents an HTTP client to communicate with Hagall Discovery Service.
func NewClient ¶
func NewClient(opts ...ClientOpts) *Client
NewClient creates new client with optional parameters.
func (*Client) DeleteServer ¶
DeleteServer unregisters a server from HDS.
func (*Client) Get ¶
Get sends a GET request to the given path and stores result in the given output.
func (*Client) GetRegistrationState ¶
GetRegistrationState returns current registration state.
func (*Client) GetRegistrationStatus ¶
func (c *Client) GetRegistrationStatus() RegistrationStatus
GetRegistrationStatus returns current registration status.
func (*Client) GetServerByEndpoint ¶
func (c *Client) GetServerByEndpoint(ctx context.Context, in GetServerByEndpointIn) (ServerResponse, error)
GetServerByEndpoint returns the server with the given endpoint from HDS.
func (*Client) GetServerByID ¶
func (c *Client) GetServerByID(ctx context.Context, in GetServerByIDIn) (ServerResponse, error)
GetServerByID returns the server with the given id from HDS.
func (*Client) GetServers ¶
func (c *Client) GetServers(ctx context.Context, in GetServersIn) (GetServersResponse, error)
GetServers returns a list of the closest servers.
func (*Client) GetWithAuth ¶
func (c *Client) GetWithAuth( ctx context.Context, path, appKey, appSecret string, queries map[string]string, out interface{}, ) error
GetWithAuth sends a GET request to the given path and stores result in the given output. It uses app key and app secret for basic authentication.
func (*Client) HandleHealthCheck ¶
func (c *Client) HandleHealthCheck(w http.ResponseWriter, r *http.Request)
HandleHealthCheck handles Hagall server health checks.
This handler is meant to be used by a Hagall server under the /health path.
func (*Client) HandleServerRegistration ¶
func (c *Client) HandleServerRegistration(w http.ResponseWriter, r *http.Request)
HandleServerRegistration handles Hagall server registration.
When a request succeeds, the Hagall server secret is stored within the client and is available by calling the Secret method.
Once the secret is transmitted, further calls to this handler result in a FORBIDDEN response.
This handler is meant to be used by a Hagall server under the /registrations path.
func (*Client) LastHealthCheck ¶
LastHealthCheck returns the time when HDS performed the latest healthcheck.
func (*Client) PostServer ¶
func (c *Client) PostServer(ctx context.Context, in PostServerIn) error
PostServer registers a server to HDS.
func (*Client) PostSession ¶
func (c *Client) PostSession(ctx context.Context, in PostSessionIn) error
PostSession registers a session to HDS.
func (*Client) SendSmokeTestResult ¶
func (c *Client) SendSmokeTestResult(ctx context.Context, results hsmoketest.SmokeTestResults) error
SendSmokeTestResult sends smoke test results to HDS /smoke-test-results endpoint.
func (*Client) SetLastHealthCheck ¶
SetLastHealthCheck set the time when HDS performed the latest healthcheck.
func (*Client) SetServerData ¶
SetServerData sets internal serverID & server secret state.
func (*Client) UserAuth ¶
func (c *Client) UserAuth(ctx context.Context, in UserAuthIn) (UserAuthResponse, error)
UserAuth auhenticates a user to a given server.
func (*Client) VerifyUserAuth ¶
VerifyUserAuth verifies a user's identity.
type ClientOpts ¶
type ClientOpts func(*Client)
func WithClientID ¶
func WithClientID(v string) ClientOpts
func WithDecoder ¶
func WithDecoder(v Decoder) ClientOpts
func WithEncoder ¶
func WithEncoder(v Encoder) ClientOpts
func WithHDSEndpoint ¶
func WithHDSEndpoint(v string) ClientOpts
func WithHagallEndpoint ¶
func WithHagallEndpoint(v string) ClientOpts
func WithPrivateKey ¶
func WithPrivateKey(v *ecdsa.PrivateKey) ClientOpts
func WithRemoteAddr ¶
func WithRemoteAddr(v string) ClientOpts
func WithSecret ¶
func WithSecret(v string) ClientOpts
func WithServerID ¶
func WithServerID(v string) ClientOpts
func WithTransport ¶
func WithTransport(v http.RoundTripper) ClientOpts
type GetServerByEndpointIn ¶
type GetServerByEndpointIn struct { Endpoint string `json:"-"` AppKey string `json:"-"` AppSecret string `json:"-"` }
GetServerByEndpointIn is the input to retrieve a server by it's endpoint from HDS.
type GetServerByIDIn ¶
type GetServerByIDIn struct { ServerID string `json:"-"` AppKey string `json:"-"` AppSecret string `json:"-"` }
GetServerByIDIn is the input to retrieve a server by it's id from HDS.
type GetServersIn ¶
type GetServersIn struct { AppKey string `json:"-"` AppSecret string `json:"-"` MinVersion string `json:"-"` Modules []string `json:"-"` FeatureFlags []string `json:"-"` }
GetServersIn is the input to get a list of the closest servers.
type GetServersResponse ¶
type GetServersResponse []ServerResponse
type GetSessionIn ¶
type GetSessionIn struct {
ID string
}
GetSessionIn is the input to get a session from HDS.
type PairIn ¶
type PairIn struct { // The Hagall server endpoint. Optional. Endpoint string // The Hagall server version. Version string // The modules that the server supports. Modules []string // The feature flags that the server supports. FeatureFlags []string // The interval between each registration try. RegistrationInterval time.Duration // The elapsed time required since the last health check to trigger a new // registration. HealthCheckTTL time.Duration // The number of retries before returning with error. RegistrationRetries int }
PairIn is the input to pair the client with HDS.
type PostServerIn ¶
type PostServerIn struct { // The Hagall server endpoint. Optional. Endpoint string `json:"endpoint"` // The endpoint URL signature signed by the wallet. EndpointSignature string `json:"endpoint_signature"` // The Hagall server version. Version string `json:"version"` // A string that represents a registration state that is used during Hagall // server verification to ensure that the registration request originates // from the server that started the registration process. State string `json:"state"` // The modules that the server supports. Modules []string `json:"modules"` // Feature flags supported by server. FeatureFlags []string `json:"feature_flags"` // The timestamp when endpoint signature was signed. Timestamp string `json:"timestamp"` }
PostServerIn represents the input to register a server to HDS.
type PostSessionIn ¶
type PostSessionIn struct {
ID string `json:"id"`
}
PostSessionIn is the input to register a session to HDS.
type RegistrationStatus ¶
type RegistrationStatus int
const ( RegistrationStatusInit RegistrationStatus = 0 RegistrationStatusRegistering RegistrationStatus = 1 RegistrationStatusPendingVerification RegistrationStatus = 2 RegistrationStatusRegistered RegistrationStatus = 3 RegistrationStatusFailed RegistrationStatus = 4 )
type ServerResponse ¶
type UserAuthIn ¶
type UserAuthIn struct { Endpoint string `json:"endpoint"` AppKey string `json:"-"` AppSecret string `json:"-"` }
UserAuthIn represents the input to authenticate to a Hagall server.
type UserAuthResponse ¶
type UserAuthResponse struct {
AccessToken string `json:"access_token"`
}