apiclient

package module
v0.0.0-...-4d6de04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2018 License: Apache-2.0 Imports: 26 Imported by: 3

README

apiclient

API client library to make request to API server.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSign

func CheckSign(values url.Values, key string, sign []byte) bool

CheckSign return true if specified sign is the signature of url values.

func EncodeValues

func EncodeValues(v url.Values) string

EncodeValues encodes the values into "URL encoded" form ("bar=baz&foo=quux") sorted by key and values. Changed from url.Values.Encode()

func FixKeepAlive

func FixKeepAlive(conn net.Conn)

REF: http://felixge.de/2014/08/26/tcp-keepalive-with-golang.html calling SetKeepAlivePeriod with an argument of 30 seconds will cause a total timeout of 10 minutes and 30 seconds for OSX (30 + 8 * 75), but 4 minutes and 30 seconds on Linux (30 + 8 * 30).

func MakeSign

func MakeSign(values url.Values, key string) []byte

MakeSign return the signature of url values signed by hmac/md5 with specified sign key.

func MakeSignString

func MakeSignString(values url.Values, key string) string

MakeSignString return the signature of url values as string signed by hmac/md5 with specified sign key.

func WebsocketCopy

func WebsocketCopy(reqConn *websocket.Conn, backendConn *websocket.Conn) error

Types

type Client

type Client struct {
	LocalAddr net.Addr

	// 网关设置,如果GWADDR为空,则通过DNS查询服务器IP
	GWURL  string
	GWADDR string

	// 签名设置,SignKey为空表示不进行签名
	AppId   string
	SignKey string

	// Nonce设置,长度为0表示不添加Nonce参数
	NonceEnabled bool
	NonceLength  int

	// 默认请求参数设置
	DefaultParams map[string]string

	// 要强制覆盖的请求参数设置
	OverrideParams map[string]string

	// 是否启用SSH隧道,如果启用而SSHClient为空,则API调用返回错误
	SSHTunnelEnabled bool
	// SSH客户端
	SSHClient *SSHClient
}

func NewClient

func NewClient(gwURL string) *Client

NewClient return a new api client.

func (*Client) Clone

func (client *Client) Clone() *Client

Clone clone a new client.

func (*Client) Get

func (client *Client) Get(action string, params url.Values, header http.Header) (*Response, error)

Get make a HTTP GET request and return as *Response.

func (*Client) GetData

func (client *Client) GetData(action string, params url.Values, header http.Header, dataKey string, data interface{}) error

func (*Client) GetResult

func (client *Client) GetResult(action string, params url.Values, header http.Header) (*api.Result, error)

func (*Client) Post

func (client *Client) Post(action string, params url.Values, header http.Header) (*Response, error)

Post make a HTTP POST request and return as *Response.

func (*Client) PostData

func (client *Client) PostData(action string, params url.Values, header http.Header, dataKey string, data interface{}) error

func (*Client) PostResult

func (client *Client) PostResult(action string, params url.Values, header http.Header) (*api.Result, error)

func (*Client) Request

func (client *Client) Request(method, action string, params url.Values, header http.Header, multipartBody io.Reader) (*Response, error)

Request make a HTTP request and return as *Response.

func (*Client) SetDefaultParam

func (client *Client) SetDefaultParam(paramName, paramValue string) *Client

SetDefaultParam set default param when request.

func (*Client) SetOverrideParam

func (client *Client) SetOverrideParam(paramName, paramValue string) *Client

SetOverrideParam set param need be override when request.

func (*Client) Upload

func (client *Client) Upload(action string, params url.Values, header http.Header, multipartBody io.Reader) (*Response, error)

Upload make a HTTP upload request and return as *Response.

func (*Client) Websocket

func (client *Client) Websocket(action string, params url.Values, header http.Header, w http.ResponseWriter, r *http.Request) (*Response, error)

Websocket make a websocket request to the backend websocket server and upgrade current request.

func (*Client) WebsocketHandleFunc

func (client *Client) WebsocketHandleFunc(action string, params url.Values, header http.Header, w http.ResponseWriter, r *http.Request,
	proxyFunc func(reqConn *websocket.Conn, backendConn *websocket.Conn) error) (*Response, error)

WebsocketFunc make a websocket request to the backend websocket server and upgrade current request, and deal with request and response by proxyFunc.

func (*Client) WsConn

func (client *Client) WsConn(action string, params url.Values, header http.Header) (*websocket.Conn, *http.Response, error)

WsConn make a websocket connection to the backend websocket server.

func (*Client) WsDial

func (client *Client) WsDial(u string, header http.Header, addr string) (ws *websocket.Conn, resp *http.Response, err error)

func (*Client) WsDialWithLocalAddr

func (client *Client) WsDialWithLocalAddr(u string, header http.Header, addr string, localAddr net.Addr) (ws *websocket.Conn, resp *http.Response, err error)

type IgnoreDeadlineConn

type IgnoreDeadlineConn struct {
	// contains filtered or unexported fields
}

ssh tunnel连接调用conn.SetDeadline会报错: tcpChan: deadline not supported 因此在此封装一层SetDeadline禁止调用

func (IgnoreDeadlineConn) Close

func (conn IgnoreDeadlineConn) Close() error

func (IgnoreDeadlineConn) LocalAddr

func (conn IgnoreDeadlineConn) LocalAddr() net.Addr

func (IgnoreDeadlineConn) Read

func (conn IgnoreDeadlineConn) Read(b []byte) (n int, err error)

func (IgnoreDeadlineConn) RemoteAddr

func (conn IgnoreDeadlineConn) RemoteAddr() net.Addr

func (IgnoreDeadlineConn) SetDeadline

func (conn IgnoreDeadlineConn) SetDeadline(t time.Time) error

func (IgnoreDeadlineConn) SetReadDeadline

func (conn IgnoreDeadlineConn) SetReadDeadline(t time.Time) error

func (IgnoreDeadlineConn) SetWriteDeadline

func (conn IgnoreDeadlineConn) SetWriteDeadline(t time.Time) error

func (IgnoreDeadlineConn) Write

func (conn IgnoreDeadlineConn) Write(b []byte) (n int, err error)

type Response

type Response struct {
	*http.Response
	// contains filtered or unexported fields
}

func (*Response) Json

func (resp *Response) Json() (*simplejson.Json, error)

Json return response as simplejson.

func (*Response) ParseData

func (resp *Response) ParseData(dataKey string, data interface{}) error

ParseData return the DATA of the result. If return code is not "ok", error return.

func (*Response) RequestId

func (resp *Response) RequestId() string

RequestId return request id in response header.

func (*Response) Result

func (resp *Response) Result() (*api.Result, error)

Result return response as api.Result.

func (*Response) String

func (resp *Response) String() (string, error)

String return response as raw string.

type SSHClient

type SSHClient struct {
	// contains filtered or unexported fields
}

func (*SSHClient) Close

func (client *SSHClient) Close() error

func (*SSHClient) Dial

func (client *SSHClient) Dial(network, addr string) (net.Conn, error)

func (*SSHClient) DialUnix

func (client *SSHClient) DialUnix(addr string) (net.Conn, error)

func (*SSHClient) WsDial

func (client *SSHClient) WsDial(network, addr string) (net.Conn, error)

func (*SSHClient) WsDialUnix

func (client *SSHClient) WsDialUnix(addr string) (net.Conn, error)

type SSHCommandConn

type SSHCommandConn struct {
	// contains filtered or unexported fields
}

func DialSSHCommand

func DialSSHCommand(session *ssh.Session, cmd string) (*SSHCommandConn, error)

ssh隧道不支持unix,需要用ssh+socat的方式来处理 ssh root@ip socat STDIO UNIX-CONNECT:/path/to/unix.sock

func (*SSHCommandConn) Close

func (conn *SSHCommandConn) Close() error

func (*SSHCommandConn) LocalAddr

func (conn *SSHCommandConn) LocalAddr() net.Addr

func (*SSHCommandConn) Read

func (conn *SSHCommandConn) Read(b []byte) (n int, err error)

func (*SSHCommandConn) RemoteAddr

func (conn *SSHCommandConn) RemoteAddr() net.Addr

func (*SSHCommandConn) SetDeadline

func (conn *SSHCommandConn) SetDeadline(t time.Time) error

func (*SSHCommandConn) SetReadDeadline

func (conn *SSHCommandConn) SetReadDeadline(t time.Time) error

func (*SSHCommandConn) SetWriteDeadline

func (conn *SSHCommandConn) SetWriteDeadline(t time.Time) error

func (*SSHCommandConn) Write

func (conn *SSHCommandConn) Write(b []byte) (n int, err error)

type SSHTunnel

type SSHTunnel struct {
	Hostname               string
	Port                   uint32
	Username               string
	AuthMethod             string
	Password               string
	IdentityFile           string
	IdentityFilePassphrase string
}

func (*SSHTunnel) Client

func (tunnel *SSHTunnel) Client() (*SSHClient, error)

func (*SSHTunnel) Clone

func (tunnel *SSHTunnel) Clone() *SSHTunnel

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL