Skip to content

Instantly share code, notes, and snippets.

@pei0804
Created July 2, 2017 13:43
Show Gist options
  • Save pei0804/7b0060159cdd849a888c35133651aa8a to your computer and use it in GitHub Desktop.
Save pei0804/7b0060159cdd849a888c35133651aa8a to your computer and use it in GitHub Desktop.
// SetGithubID ContextにGithubIDを格納する
func SetGithubID(parents context.Context, GithubID string) context.Context {
return context.WithValue(parents, ContextGithubIDKey, GithubID)
}
// GetGithubID Contextに入っているGithubIDを取り出す
func GetGithubID(ctx context.Context) (string, error) {
v := ctx.Value(ContextGithubIDKey)
token, ok := v.(string)
if !ok {
return "", fmt.Errorf("GithubID not found")
}
return token, nil
}
// 以下のように使うとカバレッジ率が下がる
githubID, err := util.GetGithubID(ctx.Context)
if err != nil {
return ctx.InternalServerError(goa.ErrInternal(err))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment