/
wax_boy
/
semaphore_custom
Обзор
Документация
Войти
/
wax_boy
/
semaphore_custom
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
api/helpers/context.go
31 строка
668 B
Denis Gukov
feat(roles): project roles
07 окт 2025, 12:23
Не верифицирован
07 окт 2025, 12:23
f90203f
Код
Авторство
О чём код?
package helpers import ( "context" "net/http" "github.com/semaphoreui/semaphore/db" ) func GetFromContext(r *http.Request, key string) any { return r.Context().Value(key) } func GetOkFromContext(r *http.Request, key string) (res any, ok bool) { res = r.Context().Value(key) return res, res != nil } func SetContextValue(r *http.Request, key string, value any) *http.Request { ctx := r.Context() ctx = context.WithValue(ctx, key, value) return r.WithContext(ctx) } func UserFromContext(r *http.Request) *db.User { return GetFromContext(r, "user").(*db.User) } func GetGlobalRole(r *http.Request) db.Role { return GetFromContext(r, "role").(db.Role) }