code: func NewSyncProducer(config *Config, sClient sarama.Client, partitioner string, wg *sync.WaitGroup) (*SyncProducer, error) {
  	if config.Debug {
  		config.Logger.SetLevel(logging.DebugLevel)
  	}
  
  	config.Logger.Debug("entering NewSyncProducer ...")
  	if err := config.ValidateSyncProducerConfig(); err != nil {
  		return nil, err
  	}
  
  	// set "RequiredAcks" for producer
  	if config.RequiredAcks == AcksUnset {
  		config.RequiredAcks = WaitForAll
  	}
  	err := setProducerRequiredAcks(config)
  	if err != nil {
  		return nil, errors.New("invalid RequiredAcks field in config")
  	}
  
  	// set partitioner
  	config.SetPartitioner(partitioner)
  
  	// initProducer object
  	sp := &SyncProducer{
  		Logger:       config.Logger,
  		Config:       config,
  		Partition:    config.Partition,
  		closed:       false,
  		closeChannel: make(chan struct{}),
  	}
  
  	// If client is nil, create a new one
  	if sClient == nil {
  		localClient, err := NewClient(config, partitioner)
  		if err != nil {
  			return nil, err
  		}
  		// store local client in syncProducer if it was created here
  		sp.Client = localClient
  		sClient = localClient
  	}
  
  	producer, err := sarama.NewSyncProducerFromClient(sClient)
  	if err != nil {
  		return nil, err
  	}
  	sp.Producer = producer
  
  	// if there is a "waitgroup" arg then use it
  	if wg != nil {
  		sp.xwg = wg
  		sp.xwg.Add(1)
  	}
  
  	return sp, nil
  }
docs: // NewSyncProducer returns a new SyncProducer instance. Producer is created from provided sarama client which can be nil;
  // in that case, a new client is created. Also the partitioner is set here. Note: provided sarama client partitioner
  // should match the one used in config.