Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth/jwt: Function names not intuitive. #526

Closed
ChrisHines opened this issue May 11, 2017 · 5 comments
Closed

auth/jwt: Function names not intuitive. #526

ChrisHines opened this issue May 11, 2017 · 5 comments

Comments

@ChrisHines
Copy link
Member

I've been using the auth/jwt package on a project for a while now and I constantly trip over the difference between FromHTTPContext and ToHTTPContext. The structure of the names don't help me remember which way the data is flowing.

From godoc:


func FromHTTPContext() http.RequestFunc

FromHTTPContext moves JWT token from context to request header. Particularly useful for clients.

func ToHTTPContext() http.RequestFunc

ToHTTPContext moves JWT token from request header to context. Particularly useful for servers.


I'd prefer the following renaming of these functions (and the corresponding gRPC pair):

FromHTTPContext -> ContextToHTTP
ToHTTPContext -> HTTPToContext

Do others find the current names confusing also?
Does anyone have better suggestions that mine?

@peterbourgon
Copy link
Member

I have no objection, but I'd ask that we also audit the other similar-sounding function names in other packages, to have a uniform style.

@basvanbeek
Copy link
Member

We have the following similar functions in Tracing:

ServerSide; pull data from header and push into Context:
FromHTTPRequest and FromGRPCRequest

ClientSide; pull data from Context and propagate in headers:
ToHTTPRequest and ToGRPCRequest

@willfaught
Copy link
Contributor

willfaught commented May 11, 2017 via email

@terinjokes
Copy link
Contributor

terinjokes commented May 11, 2017

I agree the terminology inauth/jwt is confusing, especially if you use the functions in the tracing package more often.

In tracing, you interpret the function names as "context to request" and "context from request", whereas in auth, you interpret it as "from http to context" and "to http from context".

Adapting the proposed names with the scheme used in tracing, how about:

  • RequestToContext
  • ContextToRequest

Since these functions will be called with the transport name directly to the left, we don't need to repeat ourselves.

Edit: I had the wrong context ;) in mind.

@peterbourgon
Copy link
Member

peterbourgon commented Jun 4, 2017

I believe this was fixed recently, is that true? Nope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants