github.com/godevsig/adaptiveservice@v0.9.23/service_options.go (about) 1 package adaptiveservice 2 3 // ServiceOption is option for service. 4 type ServiceOption func(*service) 5 6 // OnNewStreamFunc sets a function which is called to initialize 7 // the context when new incoming stream is accepted. 8 func OnNewStreamFunc(fn func(Context)) ServiceOption { 9 return func(svc *service) { 10 svc.fnOnNewStream = fn 11 } 12 } 13 14 // OnConnectFunc sets a function which is called when new 15 // incoming connection is established. 16 // Further message dispaching on this connection will stop 17 // if fn returns true, leaving the connection NOT closed. 18 func OnConnectFunc(fn func(Netconn) (stop bool)) ServiceOption { 19 return func(svc *service) { 20 svc.fnOnConnect = fn 21 } 22 } 23 24 // OnDisconnectFunc sets a function which is called when the connection 25 // was disconnected. 26 func OnDisconnectFunc(fn func(Netconn)) ServiceOption { 27 return func(svc *service) { 28 svc.fnOnDisconnect = fn 29 } 30 }