[GH-ISSUE #2581] [Feature Request] Support Client Service Custom Context #2058

Closed
opened 2026-05-05 13:19:34 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @clarkmcc on GitHub (Sep 17, 2021).
Original GitHub issue: https://github.com/fatedier/frp/issues/2581

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
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @clarkmcc on GitHub (Sep 17, 2021). Original GitHub issue: https://github.com/fatedier/frp/issues/2581 ### 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. ```go 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 ```go svc := client.NewService(...) svc.Run(ctx) ``` As it stands today, I have to hack my way around this ```go 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
gitea-mirror 2026-05-05 13:19:34 -06:00
  • closed this issue
  • added the
    proposal
    label
Author
Owner

@fatedier commented on GitHub (Sep 18, 2021):

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

<!-- gh-comment-id:922165954 --> @fatedier commented on GitHub (Sep 18, 2021): Yes. We are doing some code refactoring. Used as a third-party library is also one of aims.
Author
Owner

@clarkmcc commented on GitHub (Sep 18, 2021):

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?

<!-- gh-comment-id:922324910 --> @clarkmcc commented on GitHub (Sep 18, 2021): 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?
Author
Owner

@fatedier commented on GitHub (Sep 19, 2021):

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.

<!-- gh-comment-id:922488453 --> @fatedier commented on GitHub (Sep 19, 2021): > 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.
Author
Owner

@clarkmcc commented on GitHub (Jun 29, 2023):

Thank you!

<!-- gh-comment-id:1613450966 --> @clarkmcc commented on GitHub (Jun 29, 2023): Thank you!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#2058
No description provided.