@ -65,8 +65,9 @@ func (hc *httpConn) Close() error {
return nil
return nil
}
}
// DialHTTP creates a new RPC clients that connection to an RPC server over HTTP.
// DialHTTPWithClient creates a new RPC client that connects to an RPC server over HTTP
func DialHTTP ( endpoint string ) ( * Client , error ) {
// using the provided HTTP Client.
func DialHTTPWithClient ( endpoint string , client * http . Client ) ( * Client , error ) {
req , err := http . NewRequest ( http . MethodPost , endpoint , nil )
req , err := http . NewRequest ( http . MethodPost , endpoint , nil )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -76,10 +77,15 @@ func DialHTTP(endpoint string) (*Client, error) {
initctx := context . Background ( )
initctx := context . Background ( )
return newClient ( initctx , func ( context . Context ) ( net . Conn , error ) {
return newClient ( initctx , func ( context . Context ) ( net . Conn , error ) {
return & httpConn { client : new ( http . Cl ient) , req : req , closed : make ( chan struct { } ) } , nil
return & httpConn { client : cl ient, req : req , closed : make ( chan struct { } ) } , nil
} )
} )
}
}
// DialHTTP creates a new RPC client that connects to an RPC server over HTTP.
func DialHTTP ( endpoint string ) ( * Client , error ) {
return DialHTTPWithClient ( endpoint , new ( http . Client ) )
}
func ( c * Client ) sendHTTP ( ctx context . Context , op * requestOp , msg interface { } ) error {
func ( c * Client ) sendHTTP ( ctx context . Context , op * requestOp , msg interface { } ) error {
hc := c . writeConn . ( * httpConn )
hc := c . writeConn . ( * httpConn )
respBody , err := hc . doRequest ( ctx , msg )
respBody , err := hc . doRequest ( ctx , msg )