mirror of
https://github.com/datarhei/core.git
synced 2025-10-26 17:30:31 +08:00
Use own type as context key
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
// Processes is the resolver for the processes field.
|
// Processes is the resolver for the processes field.
|
||||||
func (r *queryResolver) Processes(ctx context.Context, idpattern *string, refpattern *string, group *string) ([]*models.Process, error) {
|
func (r *queryResolver) Processes(ctx context.Context, idpattern *string, refpattern *string, group *string) ([]*models.Process, error) {
|
||||||
user, _ := ctx.Value("user").(string)
|
user, _ := ctx.Value(GraphKey("user")).(string)
|
||||||
ids := r.Restream.GetProcessIDs(*idpattern, *refpattern, user, *group)
|
ids := r.Restream.GetProcessIDs(*idpattern, *refpattern, user, *group)
|
||||||
|
|
||||||
procs := []*models.Process{}
|
procs := []*models.Process{}
|
||||||
@@ -30,14 +30,14 @@ func (r *queryResolver) Processes(ctx context.Context, idpattern *string, refpat
|
|||||||
|
|
||||||
// Process is the resolver for the process field.
|
// Process is the resolver for the process field.
|
||||||
func (r *queryResolver) Process(ctx context.Context, id string, group *string) (*models.Process, error) {
|
func (r *queryResolver) Process(ctx context.Context, id string, group *string) (*models.Process, error) {
|
||||||
user, _ := ctx.Value("user").(string)
|
user, _ := ctx.Value(GraphKey("user")).(string)
|
||||||
|
|
||||||
return r.getProcess(id, user, *group)
|
return r.getProcess(id, user, *group)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Probe is the resolver for the probe field.
|
// Probe is the resolver for the probe field.
|
||||||
func (r *queryResolver) Probe(ctx context.Context, id string, group *string) (*models.Probe, error) {
|
func (r *queryResolver) Probe(ctx context.Context, id string, group *string) (*models.Probe, error) {
|
||||||
user, _ := ctx.Value("user").(string)
|
user, _ := ctx.Value(GraphKey("user")).(string)
|
||||||
|
|
||||||
probe := r.Restream.Probe(id, user, *group)
|
probe := r.Restream.Probe(id, user, *group)
|
||||||
|
|
||||||
|
|||||||
@@ -86,3 +86,5 @@ func (r *queryResolver) playoutRequest(method, addr, path, contentType string, d
|
|||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GraphKey string
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func (g *GraphHandler) Query(c echo.Context) error {
|
|||||||
user, _ := c.Get("user").(string)
|
user, _ := c.Get("user").(string)
|
||||||
|
|
||||||
r := c.Request()
|
r := c.Request()
|
||||||
ctx := context.WithValue(r.Context(), "user", user)
|
ctx := context.WithValue(r.Context(), resolver.GraphKey("user"), user)
|
||||||
|
|
||||||
g.queryHandler.ServeHTTP(c.Response(), r.WithContext(ctx))
|
g.queryHandler.ServeHTTP(c.Response(), r.WithContext(ctx))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user