mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 08:05:49 -06:00
[GH-ISSUE #1407] Package naming is too generic for a library #1110
Labels
No labels
In Progress
WIP
WaitingForInfo
bug
doc
duplicate
easy
enhancement
future
help wanted
invalid
lifecycle/stale
need-issue-template
need-usage-help
no plan
proposal
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/frp#1110
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @velovix on GitHub (Aug 24, 2019).
Original GitHub issue: https://github.com/fatedier/frp/issues/1407
Package names like
server,client, andconfigmake a lot of sense for internal development of FRP, but are too generic when FRP is used as a library in another system. When reading non-FRP code, it's not clear that these names are related to FRP.To address this, a new package could be created, maybe named
frp, where all interfaces intended to be used as a library are stored. Code could be migrated to this new package or we could use type aliases, like this:This would give us a lot of control over which APIs should be exposed for library usage and which should not, and would lead to less ambiguous naming for users. Compare
server.Servicetofrp.Server.I'm not sure whether type aliasing or code migration is more preferable. My first impression is that I would rather migrate the code as I think it would lead to more code clarity. Internal types like
server.Controlwould stay where they are, as I don't think there's any reason why a library user would need them.If this or an alternative proposal that addresses the same problem looks good, I would be happy to send a pull request.
@fatedier commented on GitHub (Aug 25, 2019):
I think it's common to import
github.com/fatedier/frp/serverand callserver.NewServiceor import
github.com/fatedier/frp/clientand callclient.NewService。frpis included in the import path, you know it when you import this package.You can also change import path to this format:
So it looks like
frps.NewServiceandfrpc.NewService。I prefer not to affect current code structure.
@velovix commented on GitHub (Aug 26, 2019):
That's true, but it requires that you look at the import path to find out what server or client we're talking about in code, which seems like an ergonomics problem to me.
As an example, the standard library uses the package name
net/http, so users typehttp.Clientandhttp.Server. What makesnet/httpunique isn't that it provides a server and client, lots of packages do that. What makes it unique is that it offers HTTP implementations of network concepts. I think the same reasoning holds for FRP.I also think that these names don't fit with this guideline from the Package Names blog post:
This is a decent solution, and the one I will probably use if the current package naming scheme stays the way it is.
I respect that, and I understand that FRP is a tool first and a library second. I'm hoping that the aliasing solution would be a reasonable middle ground, because it allows for current code structure to remain the same while exposing a select group of APIs in a way that's more consumable as a library.
@fatedier commented on GitHub (Aug 27, 2019):
OK. Maybe we can create a new package
sdk/frpwithclient.go,server.goandconfig.go.Type alias and nested structs are all optional.
@velovix commented on GitHub (Oct 28, 2019):
Unfortunately, we're no longer using FRP, so I don't have a good use-case to work on these kinds of issues anymore. Please feel free to close this issue if you don't foresee anybody else wanting to use FRP as a library.
@fatedier commented on GitHub (Oct 29, 2019):
Just keep it open, it may help other peoples with same requirement.
Thanks for all your contribution.
@0x76long commented on GitHub (Aug 4, 2021):
支持 go mod 模式引入吗