dgrijalva/jwt-go — pull request #46 by albrow (2014-12-27 19:27:28+00:00)
Title: Reference signing methods directly instead of by a string name

First, let me say that this is a great library! I've been using it in a project for the past
week or so and have pretty much no complaints. Thank you!

I made the following change:

When possible, instead of identifying signing methods by string, pass
them in directly by name. This is less error-prone and avoids an unnecessary
map lookup. Also encourage this type of usage by using it in the README.

### What?

I replaced several instances of code like this:

``` go
token := jwt.New(jwt.GetSigningMethod("HS256"))
```

With this:

``` go
token := jwt.New(SigningMethodHS256)
```

### Why?

When parsing a jwt token, you have to use the string name of a signing method, since
that is what is encoded into the "alg" claim in the token. However, this is not always necessary.
When you're not parsing a token, it is better to reference the signing methods directly instead of
using a string identifiers.

1. Your text editor/IDE does not know how to autocomplete a string.
2. If you make a typo with the string name, it's a runtime error. But if you make a typo with
the signing method name (the object itself), it's a compile-time error. Catching errors faster is better.
3. This avoids an unnecessary lookup in the signing methods map. Making code simpler and giving
(slightly) better performance.
4. It turns out to use less characters and less function calls.

I understand this is a pretty small change (maybe even seemingly insignificant). But I consider this
a small improvement to an already good library, and I don't see any downsides. I would greatly appreciate
it if you accept this.

Cheers!