58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package fasthttp
 | 
						|
 | 
						|
import (
 | 
						|
	"github.com/gorilla/websocket"
 | 
						|
 | 
						|
	"git.loafle.net/commons_go/rpc"
 | 
						|
	"git.loafle.net/commons_go/rpc/protocol"
 | 
						|
	cwf "git.loafle.net/commons_go/websocket_fasthttp"
 | 
						|
)
 | 
						|
 | 
						|
type ServletHandlers struct {
 | 
						|
}
 | 
						|
 | 
						|
func (sh *ServletHandlers) GetRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {
 | 
						|
	soc := conn.(cwf.Socket)
 | 
						|
	_, r, err := soc.NextReader()
 | 
						|
 | 
						|
	requestCodec, err := codec.NewRequest(r)
 | 
						|
 | 
						|
	return requestCodec, err
 | 
						|
}
 | 
						|
 | 
						|
func (sh *ServletHandlers) SendResponse(servletCTX rpc.ServletContext, conn interface{}, requestCodec protocol.ServerRequestCodec, result interface{}, err error) error {
 | 
						|
	soc := conn.(cwf.Socket)
 | 
						|
 | 
						|
	wc, wErr := soc.NextWriter(websocket.TextMessage)
 | 
						|
	if nil != wErr {
 | 
						|
		return wErr
 | 
						|
	}
 | 
						|
 | 
						|
	if nil != err {
 | 
						|
		if wErr := requestCodec.WriteError(wc, 500, err); nil != wErr {
 | 
						|
			return wErr
 | 
						|
		}
 | 
						|
	} else {
 | 
						|
		if wErr := requestCodec.WriteResponse(wc, result); nil != wErr {
 | 
						|
			return wErr
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 | 
						|
 | 
						|
func (sh *ServletHandlers) SendNotification(servletCTX rpc.ServletContext, conn interface{}, codec protocol.ServerCodec, method string, args ...interface{}) error {
 | 
						|
	soc := conn.(cwf.Socket)
 | 
						|
 | 
						|
	wc, wErr := soc.NextWriter(websocket.TextMessage)
 | 
						|
	if nil != wErr {
 | 
						|
		return wErr
 | 
						|
	}
 | 
						|
 | 
						|
	if wErr := codec.WriteNotification(wc, method, args); nil != wErr {
 | 
						|
		return wErr
 | 
						|
	}
 | 
						|
 | 
						|
	return nil
 | 
						|
}
 |