You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: s2a.go
    path of file: ./repos/plik/vendor/github.com/google/s2a-go
    
    the code of the file until where you have to start completion: /*
 *
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

// Package s2a provides the S2A transport credentials used by a gRPC
// application.
package s2a

import (
	"context"
	"crypto/tls"
	"errors"
	"fmt"
	"net"
	"sync"
	"time"

	"github.com
    
func NewS2ADialTLSContextFunc(opts *ClientOptions) func(ctx context.Context, network, addr string) (net.Conn, error) {

	return func(ctx context.Context, network, addr string) (net.Conn, error) {

		fallback := func(err error) (net.Conn, error) {
			if opts.FallbackOpts != nil && opts.FallbackOpts.FallbackDialer != nil &&
				opts.FallbackOpts.FallbackDialer.Dialer != nil && opts.FallbackOpts.FallbackDialer.ServerAddr != "" {
				fbDialer := opts.FallbackOpts.FallbackDialer
				grpclog.Infof("fall back to dial: %s", fbDialer.ServerAddr)
				fbConn, fbErr := fbDialer.Dialer.DialContext(ctx, network, fbDialer.ServerAddr)
				if fbErr != nil {
					return nil, fmt.Errorf("error fallback to %s: %v; S2A error: %w", fbDialer.ServerAddr, fbErr, err)
				}
				return fbConn, nil
			}
			return nil, err
		}

		factory, err := NewTLSClientConfigFactory(opts)
		if err != nil {
			grpclog.Infof("error creating S2A client config factory: %v", err)
			return fallback(err)
		}

		serverName, _, err := net.SplitHostPort(addr)
		if err != nil {
			serverName = addr
		}
		timeoutCtx, cancel := context.WithTimeout(ctx, v2.GetS2ATimeout())
		defer cancel()
		s2aTLSConfig, err := factory.Build(timeoutCtx, &TLSClientConfigOptions{
			ServerName: serverName,
		})
		if err != nil {
			grpclog.Infof("error building S2A TLS config: %v", err)
			return fallback(err)
		}

		s2aDialer := &tls.Dialer{
			Config: s2aTLSConfig,
		}
		c, err := s2aDialer.DialContext(ctx, network, addr)
		if err != nil {
			grpclog.Infof("error dialing with S2A to %s: %v", addr, err)
			return fallback(err)
		}
		grpclog.Infof("success dialing MTLS to %s with S2A", addr)
		return c, nil
	}
}