github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/rpc/inproc.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package rpc 13 14 import ( 15 "context" 16 "net" 17 ) 18 19 // NewInProcClient attaches an in-process connection to the given RPC server. 20 func DialInProc(handler *Server) *Client { 21 initctx := context.Background() 22 c, _ := newClient(initctx, func(context.Context) (net.Conn, error) { 23 p1, p2 := net.Pipe() 24 go handler.ServeCodec(NewJSONCodec(p1), OptionMethodInvocation|OptionSubscriptions) 25 return p2, nil 26 }) 27 return c 28 }