~handlerug/handlebot

ref: e2138e35984f582b50a481b58c332afae2841b1f handlebot/wolframalpha/context.go -rw-r--r-- 434 bytes
e2138e35Umar Getagazov urlpreview: Parse Content-Disposition 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package wolframalpha

import (
	"context"
	"errors"
)

var waCtxKey = &contextKey{"wolframalpha"}

type contextKey struct {
	name string
}

func Context(ctx context.Context, wa *Client) context.Context {
	return context.WithValue(ctx, waCtxKey, wa)
}

func ForContext(ctx context.Context) *Client {
	client, ok := ctx.Value(waCtxKey).(*Client)
	if !ok {
		panic(errors.New("Invalid Wolfram|Alpha client context"))
	}
	return client
}