Skip to content

Commit 4e7c476

Browse files
committed
internal/config: add Config.Clone()
1 parent 084ebd6 commit 4e7c476

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

internal/config/options.go

+37-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/tls"
66
"net"
7+
"slices"
78
"time"
89

910
"github.com/domainr/epp2/internal"
@@ -17,22 +18,54 @@ type Options interface {
1718
// Config is an optimized form of EPP options,
1819
// suitable for passing via the call stack.
1920
type Config struct {
20-
Context context.Context
21-
KeepAlive time.Duration
22-
Timeout time.Duration
21+
Context context.Context
22+
23+
// Network options
2324
Dialer ContextDialer
2425
TLSConfig *tls.Config
26+
KeepAlive time.Duration
27+
Timeout time.Duration
2528
Pipeline int
26-
Schemas schema.Schemas
29+
30+
// EPP options
31+
Versions []string
32+
Objects []string
33+
Extensions []string
34+
UnannouncedExtensions []string
35+
Schemas schema.Schemas
2736
}
2837

2938
func (*Config) EPPOptions(internal.Internal) {}
3039

40+
// Clone returns a 1-level deep clone of cfg.
41+
// Slice members and tls.Config will be cloned.
42+
func (cfg *Config) Clone() *Config {
43+
return &Config{
44+
Context: cfg.Context,
45+
46+
// Network options
47+
Dialer: cfg.Dialer,
48+
TLSConfig: cfg.TLSConfig.Clone(),
49+
KeepAlive: cfg.KeepAlive,
50+
Timeout: cfg.Timeout,
51+
Pipeline: cfg.Pipeline,
52+
53+
// EPP options
54+
Versions: slices.Clone(cfg.Versions),
55+
Objects: slices.Clone(cfg.Objects),
56+
Extensions: slices.Clone(cfg.Extensions),
57+
UnannouncedExtensions: slices.Clone(cfg.UnannouncedExtensions),
58+
Schemas: slices.Clone(cfg.Schemas),
59+
}
60+
}
61+
3162
func (cfg *Config) Join(opts ...Options) {
3263
for _, src := range opts {
3364
switch src := src.(type) {
3465
case nil:
3566
continue
67+
case *Config:
68+
*cfg = *(src.Clone())
3669
case Context:
3770
cfg.Context = src.Context
3871
case KeepAlive:

0 commit comments

Comments
 (0)