From 435d55e9ac3226c28c71d2d495e2da12311b10a5 Mon Sep 17 00:00:00 2001 From: ujuzy Date: Fri, 6 May 2022 00:05:31 +0300 Subject: [PATCH] telegram header --- auth/middleware.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/auth/middleware.go b/auth/middleware.go index 351189a..f17901e 100644 --- a/auth/middleware.go +++ b/auth/middleware.go @@ -12,8 +12,9 @@ import ( ) const ( - UserKey = "X-Auth-User" - TokenKey = "X-Auth-Token" + UserKey = "X-Auth-User" + TokenKey = "X-Auth-Token" + TelegramKey = "X-Auth-Telegram" ) type userInfo struct { @@ -76,3 +77,17 @@ func GetUserInfo(ctx context.Context) (*userInfo, error) { return &user, nil } + +func GetTelegramUsername(ctx context.Context) (string, error) { + md, ok := metadata.FromIncomingContext(ctx) + if !ok { + return "", status.Errorf(codes.InvalidArgument, "Retrieving metadata is failed") + } + + tgHeader, ok := md[strings.ToLower(TelegramKey)] + if !ok { + return "", nil + } + + return tgHeader[0], nil +}