Skip to content

Commit

Permalink
Remove need to return errors in opt functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Sep 6, 2024
1 parent e80ccc3 commit 6e330fa
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package service

import (
"context"
"fmt"
"net"
"time"

Expand All @@ -43,7 +42,7 @@ type Service interface {
}

// Option user's option.
type Option func(s *ssService) error
type Option func(s *ssService)

type ssService struct {
m ServiceMetrics
Expand All @@ -59,9 +58,7 @@ func NewService(opts ...Option) (Service, error) {
s := &ssService{}

for _, opt := range opts {
if err := opt(s); err != nil {
return nil, fmt.Errorf("failed to create new service: %v", err)
}
opt(s)
}

if s.natTimeout == 0 {
Expand All @@ -72,32 +69,28 @@ func NewService(opts ...Option) (Service, error) {

// WithCiphers option function.
func WithCiphers(ciphers CipherList) Option {
return func(s *ssService) error {
return func(s *ssService) {
s.ciphers = ciphers
return nil
}
}

// WithMetrics option function.
func WithMetrics(metrics ServiceMetrics) Option {
return func(s *ssService) error {
return func(s *ssService) {
s.m = metrics
return nil
}
}

// WithReplayCache option function.
func WithReplayCache(replayCache *ReplayCache) Option {
return func(s *ssService) error {
return func(s *ssService) {
s.replayCache = replayCache
return nil
}
}

func WithNatTimeout(natTimeout time.Duration) Option {
return func(s *ssService) error {
return func(s *ssService) {
s.natTimeout = natTimeout
return nil
}
}

Expand Down

0 comments on commit 6e330fa

Please sign in to comment.