Documentation ¶
Index ¶
- Constants
- type Auth
- type Bridge
- type CallOpts
- type Header
- type Helper
- func (h *Helper) GetIntParam(key string) int64
- func (h *Helper) GetParam(key string) string
- func (h *Helper) HTTPCall(method, url string, obj interface{}) error
- func (h *Helper) HTTPCallRawWithOpts(method, url string, opts CallOpts) ([]byte, error)
- func (h *Helper) HTTPCallRawWithOptsWithContext(ctx context.Context, method, url string, opts CallOpts) ([]byte, error)
- func (h *Helper) HTTPCallWithContext(ctx context.Context, method, url string, obj interface{}) error
- func (h *Helper) HTTPCallWithOpts(method, url string, obj interface{}, opts CallOpts) error
- func (h *Helper) HTTPCallWithOptsWithContext(ctx context.Context, method, url string, obj interface{}, opts CallOpts) error
- type JSON
- type Opts
- type Param
- type Result
- type Server
Constants ¶
const ( AuthParam = "param" AuthHeader = "header" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
Auth is the generic interface for how the client passes in their API key for authentication
type CallOpts ¶
type CallOpts struct { Auth Auth `json:"-"` Query map[string]interface{} `json:"query"` QueryPassthrough bool `json:"queryPassthrough"` Body string `json:"body"` ExpectedCode int `json:"expectedCode"` }
CallOpts are the options given into a http call method
type Header ¶
Header is the Auth implementation that requires a header to be set
func (*Header) Authenticate ¶
Authenticate takes the key and value given and sets it as a header
type Helper ¶
type Helper struct { Data *JSON // contains filtered or unexported fields }
Helper is given to the receiving bridge to use on run, giving the bridge the visibility to the input parameters from the node request and having simple functions for making http calls.
func (*Helper) GetIntParam ¶
GetIntParam gets the int64 value of a key in the `data` JSON object that is given on request by the Chainlink node
func (*Helper) GetParam ¶
GetIntParam gets the string value of a key in the `data` JSON object that is given on request by the Chainlink node
func (*Helper) HTTPCallRawWithOpts ¶
HTTPCallRawWithOpts performs a HTTP call with any method and returns the raw byte body and any error Supported options:
- Authentication methods for the API (query param, headers)
- Query parameters via `opts.Query`
- Passthrough through all json keys within the request `data` object via `opts.QueryPassthrough`
- Pass in a body to send with the request via `opts.Body`
- Send in post form kv via `opts.PostForm`
- Return an error if the returning http status code is different to `opts.ExpectedCode`
func (*Helper) HTTPCallRawWithOptsWithContext ¶
func (*Helper) HTTPCallWithContext ¶
func (*Helper) HTTPCallWithOpts ¶
HTTPCallWithOpts mirrors HTTPCallRawWithOpts bar the returning byte body is unmarshalled into a given object pointer
type JSON ¶
Based on https://github.com/smartcontractkit/chainlink/blob/master/core/store/models/common.go#L128
func ParseInterface ¶
ParseInterface attempts to coerce the input interface and parse it into a JSON object.
func (*JSON) MarshalJSON ¶
MarshalJSON returns the JSON data if it already exists, returns an empty JSON object as bytes if not.
func (*JSON) UnmarshalJSON ¶
UnmarshalJSON parses the JSON bytes and stores in the *JSON pointer.
type Opts ¶
type Opts struct { Name string `json:"name"` Path string `json:"path"` Lambda bool `json:"Lambda"` }
Opts is the options for each bridge
type Param ¶
Query is the Auth implementation that requires GET param set
func (*Param) Authenticate ¶
Authenticate takes the `apikey` in the GET param and then authenticates it with the KeyManager
type Result ¶
type Result struct { JobRunID string `json:"jobRunId"` ID string `json:"id,omitempty"` TaskRunID string `json:"taskRunId,omitempty"` Status string `json:"status"` Error null.String `json:"error"` Pending bool `json:"pending"` Data *JSON `json:"data"` }
Result represents a Chainlink JobRun
func (*Result) SetCompleted ¶
func (r *Result) SetCompleted()
SetCompleted marks a result as completed
func (*Result) SetErrored ¶
SetCompleted marks a result as errored
func (*Result) SetJobRunID ¶
func (r *Result) SetJobRunID()
SetJobRunID sets the request's ID to the result's Job Run ID. If "jobRunId" is supplied in the request, use that for the response.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds pointers to the bridges indexed by their paths and the bridge to be mounted in Lambda.
func NewServer ¶
NewServer returns a new Server with the bridges in a map indexed by its path. Once returned, the server can be started to listen for any new requests.
If a bridge is passed in that has a duplicate path then the last one with that path will be mounted.
Any bridge with an empty path gets assigned "/" to avoid panics on start.
func (*Server) Handler ¶
func (s *Server) Handler(w http.ResponseWriter, r *http.Request)
Hander is of http.Handler type, receiving any inbound requests from the HTTP server when the bridge is ran local
func (*Server) Mux ¶
HTTPMux returns the http.Handler for the go http multiplexer, registering all the bridges paths with the handler
func (*Server) Start ¶
Start the bridge server. Routing on how the server is started is determined which platform is specified by the end user. Currently supporting:
- Inbuilt http (default)
- AWS Lambda (env LAMBDA=1)
Port only has to be passed in if the inbuilt HTTP server is being used.
If the inbuilt http server is being used, bridges can specify many external adaptors as long if exclusive paths are given.
If multiple adaptors are included with Lambda/gcp enabled, then the first bridge that has it enabled will be given as the Handler.