Beispiel #1
0
// Method with named params and TCP context.
func (*CtxSvc) NameCtx(t NameArgContext, res *NameResCtx) error {
	*res = NameResCtx{Name: t.Fname + " " + t.Lname}
	if val := t.Context().Value(remoteAddrContextKey); val != nil {
		res.TCPRemoteAddr, _, _ = net.SplitHostPort(val.(*net.TCPAddr).String())
	}
	if val := jsonrpc2.HTTPRequestFromContext(t.Context()); val != nil {
		res.HTTPRemoteAddr, _, _ = net.SplitHostPort(val.RemoteAddr)
	}
	return nil
}
Beispiel #2
0
// Method with named params and HTTP context.
func (*ExampleSvc) FullName3(t NameArgContext, res *NameRes) error {
	host, _, _ := net.SplitHostPort(jsonrpc2.HTTPRequestFromContext(t.Context()).RemoteAddr)
	fmt.Printf("FullName3(): Remote IP is %s\n", host)
	*res = NameRes{t.Fname + " " + t.Lname}
	return nil
}