...
1 package sock
2
3 import (
4 "context"
5
6 "github.com/tetratelabs/wazero/internal/sock"
7 )
8
9
10
11
12
13
14 type Config interface {
15
16 WithTCPListener(host string, port int) Config
17 }
18
19
20 func NewConfig() Config {
21 return &internalSockConfig{c: &sock.Config{}}
22 }
23
24
25
26 type internalSockConfig struct {
27 c *sock.Config
28 }
29
30
31 func (c *internalSockConfig) WithTCPListener(host string, port int) Config {
32 cNew := c.c.WithTCPListener(host, port)
33 return &internalSockConfig{cNew}
34 }
35
36
37 func WithConfig(ctx context.Context, config Config) context.Context {
38 if config, ok := config.(*internalSockConfig); ok && len(config.c.TCPAddresses) > 0 {
39 return context.WithValue(ctx, sock.ConfigKey{}, config.c)
40 }
41 return ctx
42 }
43
View as plain text