2020-03-04 16:55:13 +01:00
|
|
|
package imgsource
|
|
|
|
|
|
2020-03-11 14:18:25 +01:00
|
|
|
import (
|
|
|
|
|
"context"
|
2021-04-29 11:58:50 +02:00
|
|
|
"io"
|
2020-03-11 14:18:25 +01:00
|
|
|
)
|
2020-03-04 16:55:13 +01:00
|
|
|
|
2020-05-06 13:56:29 +02:00
|
|
|
type key int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
auth key = iota
|
|
|
|
|
)
|
|
|
|
|
|
2020-03-04 16:55:13 +01:00
|
|
|
// Source defines the interface for image sources
|
|
|
|
|
type Source interface {
|
2021-04-29 11:58:50 +02:00
|
|
|
Get(ctx context.Context, path string) (io.ReadCloser, error)
|
2020-03-04 16:55:13 +01:00
|
|
|
}
|
2020-05-06 13:56:29 +02:00
|
|
|
|
2020-11-26 16:36:51 +01:00
|
|
|
// ContextSetAuthorization puts the authorization in the context.
|
|
|
|
|
func ContextSetAuthorization(parent context.Context, authorization string) context.Context {
|
2020-05-06 13:56:29 +02:00
|
|
|
return context.WithValue(parent, auth, authorization)
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-26 16:36:51 +01:00
|
|
|
// ContextGetAuthorization gets the authorization from the context.
|
|
|
|
|
func ContextGetAuthorization(ctx context.Context) (string, bool) {
|
2020-05-06 13:56:29 +02:00
|
|
|
val := ctx.Value(auth)
|
|
|
|
|
if val == nil {
|
2020-11-26 16:36:51 +01:00
|
|
|
return "", false
|
2020-05-06 13:56:29 +02:00
|
|
|
}
|
2020-11-26 16:36:51 +01:00
|
|
|
return val.(string), true
|
2020-05-06 13:56:29 +02:00
|
|
|
}
|