github.com/blend/go-sdk@v1.20220411.3/proxyprotocol/create_listener_options.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package proxyprotocol 9 10 import ( 11 "crypto/tls" 12 "time" 13 ) 14 15 // CreateListenerOptions are the options for creating listeners. 16 type CreateListenerOptions struct { 17 TLSConfig *tls.Config 18 UseProxyProtocol bool 19 KeepAlive bool 20 KeepAlivePeriod time.Duration 21 } 22 23 // CreateListenerOption is a mutator for the options used when creating a listener. 24 type CreateListenerOption func(*CreateListenerOptions) error 25 26 // OptTLSConfig sets the listener tls config. 27 func OptTLSConfig(tlsConfig *tls.Config) CreateListenerOption { 28 return func(clo *CreateListenerOptions) error { 29 clo.TLSConfig = tlsConfig 30 return nil 31 } 32 } 33 34 // OptUseProxyProtocol sets if we should decode proxy protocol or not. 35 func OptUseProxyProtocol(useProxyProtocol bool) CreateListenerOption { 36 return func(clo *CreateListenerOptions) error { 37 clo.UseProxyProtocol = useProxyProtocol 38 return nil 39 } 40 } 41 42 // OptKeepAlive sets if we should keep TCP connections alive or not. 43 func OptKeepAlive(keepAlive bool) CreateListenerOption { 44 return func(clo *CreateListenerOptions) error { 45 clo.KeepAlive = keepAlive 46 return nil 47 } 48 } 49 50 // OptKeepAlivePeriod sets the duration we should keep connections alive for. 51 func OptKeepAlivePeriod(keepAlivePeriod time.Duration) CreateListenerOption { 52 return func(clo *CreateListenerOptions) error { 53 clo.KeepAlivePeriod = keepAlivePeriod 54 return nil 55 } 56 }