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

ContextService type for SimpleServer #21

Merged
merged 1 commit into from
Jan 6, 2016
Merged

Conversation

gaplyk
Copy link
Contributor

@gaplyk gaplyk commented Jan 6, 2016

New context Service which using "golang.org/x/net/context"

  • context service
  • simple test for context service
  • generation of request-id and putting it to context

ctx = context.WithValue(ctx, "forward-for-ip", ip)
}

id, err := GenerateRequestID()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other folks may start adding additional tracing via go-kit/kit/tracing or some other tooling so we might not want to have this in here by default.

Would you mind abstracting this chunk with the RequestID into a middleware func? Then you can just add it into the ContextMiddleware method of your ContextService implementation.

Also, for the context keys, would you mind creating a separate type for them? I'd like us to match the pattern covered in the Go context blog post. (example: https://blog.golang.org/context/userip/userip.go)

@jprobinson
Copy link
Contributor

Great start, @gaplyk!

After you make your changes, mind squashing your commits? http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html

}

var (
cancel context.CancelFunc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind changing it to a one liner since we only have a single variable being declared?

type ContextKey int

// UserIPKey is key to set/retrieve value from context
const UserIPKey contextKey = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind tossing the consts in a const ( ) block? Just visually groups them together a bit more.

@gaplyk gaplyk force-pushed the master branch 2 times, most recently from 40b5380 to ffc30c2 Compare January 6, 2016 21:41
@@ -62,3 +63,25 @@ type RPCService interface {

// JSONEndpoint is the JSONService equivalent to SimpleService's http.HandlerFunc.
type JSONEndpoint func(*http.Request) (int, interface{}, error)

// ContextService is an interface defining a service that
// is made up of ContextHandler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding periods to these comments?

jprobinson added a commit that referenced this pull request Jan 6, 2016
ContextService type for SimpleServer
@jprobinson jprobinson merged commit 9c23a01 into nytimes:master Jan 6, 2016
@jprobinson
Copy link
Contributor

Thanks, @gaplyk! 💥

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

Successfully merging this pull request may close these issues.

None yet

3 participants