frp icon indicating copy to clipboard operation
frp copied to clipboard

[Feature Request] Support Client Service Custom Context

Open clarkmcc opened this issue 2 years ago • 3 comments

Describe the feature request

First of all, this is a fantastic project. We use this as a library, and I hope that in the future it will be better designed to support usage as a library. When creating a new client service, I do not have the option to pass in my own context, rather the service struct creates and maintains it's own context.

func NewService(cfg config.ClientCommonConf, pxyCfgs map[string]config.ProxyConf, visitorCfgs map[string]config.VisitorConf, cfgFile string) (svr *Service, err error) {
	ctx, cancel := context.WithCancel(context.Background())
	svr = &Service{

It would be easier if I could specify my own context like this

svc := client.NewService(...)
svc.Run(ctx)

As it stands today, I have to hack my way around this

svc := client.NewService(...)
go func() {
    <-ctx.Done()
   svc.Close()
}
svc.Run()

Describe alternatives you've considered

No response

Affected area

  • [ ] Docs
  • [ ] Installation
  • [ ] Performance and Scalability
  • [ ] Security
  • [X] User Experience
  • [ ] Test and Release
  • [ ] Developer Infrastructure
  • [X] Client Plugin
  • [ ] Server Plugin
  • [ ] Extensions
  • [ ] Others

clarkmcc avatar Sep 17 '21 19:09 clarkmcc

Yes. We are doing some code refactoring. Used as a third-party library is also one of aims.

fatedier avatar Sep 18 '21 02:09 fatedier

Unrelated but are there plans to clean up the logging implementation and use a simple interface rather than registering named loggers and then configuring which named logger to use?

clarkmcc avatar Sep 18 '21 15:09 clarkmcc

Unrelated but are there plans to clean up the logging implementation and use a simple interface rather than registering named loggers and then configuring which named logger to use?

Good point.

fatedier avatar Sep 19 '21 15:09 fatedier

Thank you!

clarkmcc avatar Jun 29 '23 15:06 clarkmcc