isle/go/daemon/ctx.go

21 lines
613 B
Go
Raw Normal View History

package daemon
import (
"context"
"isle/daemon/jsonrpc2"
)
const metaKeyNetworkSearchStr = "daemon.networkSearchStr"
// WithNetwork returns the Context so that, when used against a daemon RPC
// endpoint, the endpoint knows which network is being targetted for the call.
// The network can be identified by its ID, name, or domain.
func WithNetwork(ctx context.Context, searchStr string) context.Context {
return jsonrpc2.WithMeta(ctx, metaKeyNetworkSearchStr, searchStr)
}
func getNetworkSearchStr(ctx context.Context) string {
v, _ := jsonrpc2.GetMeta(ctx)[metaKeyNetworkSearchStr].(string)
return v
}