-
-
Save pei0804/7b0060159cdd849a888c35133651aa8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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