code: func handleSetGenerate(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
  	c := cmd.(*btcjson.SetGenerateCmd)
  
  	// Disable generation regardless of the provided generate flag if the
  	// maximum number of threads (goroutines for our purposes) is 0.
  	// Otherwise enable or disable it depending on the provided flag.
  	generate := c.Generate
  	genProcLimit := -1
  	if c.GenProcLimit != nil {
  		genProcLimit = *c.GenProcLimit
  	}
  	if genProcLimit == 0 {
  		generate = false
  	}
  
  	if !generate {
  		s.cfg.CPUMiner.Stop()
  	} else {
  		// Respond with an error if there are no addresses to pay the
  		// created blocks to.
  		if len(cfg.miningAddrs) == 0 {
  			return nil, &btcjson.RPCError{
  				Code: btcjson.ErrRPCInternal.Code,
  				Message: "No payment addresses specified " +
  					"via --miningaddr",
  			}
  		}
  
  		// It's safe to call start even if it's already started.
  		s.cfg.CPUMiner.SetNumWorkers(int32(genProcLimit))
  		s.cfg.CPUMiner.Start()
  	}
  	return nil, nil
  }
docs: // handleSetGenerate implements the setgenerate command.