github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/server/process_config.go (about)

     1  package server
     2  
     3  import (
     4  	"github.com/nyan233/littlerpc/core/common/errorhandler"
     5  	"strings"
     6  	"unsafe"
     7  )
     8  
     9  type RpcServer struct {
    10  	Prefix string
    11  	s      *Server
    12  }
    13  
    14  func (r *RpcServer) init(prefix string, s *Server) {
    15  	r.Prefix = prefix
    16  	r.s = s
    17  }
    18  
    19  func (r *RpcServer) Setup() {
    20  	return
    21  }
    22  
    23  func (r *RpcServer) HijackProcess(name string, fn func(stub *Stub)) error {
    24  	pName := strings.Join([]string{r.Prefix, name}, ".")
    25  	process, ok := r.s.services.LoadOk(pName)
    26  	if !ok {
    27  		return errorhandler.ServiceNotfound
    28  	}
    29  	process.Hijack = true
    30  	process.Hijacker = unsafe.Pointer(&fn)
    31  	return nil
    32  }