func (s *Service) GetNodeAPIURL() string {
	s.mu.RLock()
	defer s.mu.RUnlock()
	scheme := "http"
	if s.https {
		scheme = "https"
	}
	return fmt.Sprintf("%s://%s", scheme, s.apiAddr)
}
GetNodeAPIURL returns fully-specified HTTP(S) API URL for the
node running this service.
package cluster
import (
	"encoding/binary"
	"expvar"
	"fmt"
	"io"
	"log"
	"net"
	"os"
	"strconv"
	"sync"
	"time"
	"github.com/golang/protobuf/proto"
	"github.com/rqlite/rqlite/command"
)
var stats *expvar.Map
const (
	numGetNodeAPIRequest  = "num_get_node_api_req"
	numGetNodeAPIResponse = "num_get_node_api_resp"
	numExecuteRequest     = "num_execute_req"
	numQueryRequest       = "num_query_req"
	numGetNodeAPIRequestLocal = "num_get_node_api_req_local"
)
const (
	MuxRaftHeader = 1
	MuxClusterHeader = 2  
)
func init() {
	stats = expvar.NewMap("cluster")
	stats.Add(numGetNodeAPIRequest, 0)
	stats.Add(numGetNodeAPIResponse, 0)
	stats.Add(numExecuteRequest, 0)
	stats.Add(numQueryRequest, 0)
	stats.Add(numGetNodeAPIRequestLocal, 0)
}
type Dialer interface {
	Dial(address string, timeout time.Duration) (net.Conn, error)
}
type Database interface {
	Execute(er *command.ExecuteRequest) ([]*command.ExecuteResult, error)
	Query(qr *command.QueryRequest) ([]*command.QueryRows, error)
}
type Transport interface {
	net.Listener
	Dialer
}
type Service struct {
	tn   Transport  
	addr net.Addr   
	db Database  
	mu      sync.RWMutex
	https   bool    
	apiAddr string  
	logger *log.Logger
}
func New(tn Transport, db Database) *Service {
	return &Service{
		tn:     tn,
		addr:   tn.Addr(),
		db:     db,
		logger: log.New(os.Stderr, "[cluster] ", log.LstdFlags),
	}
}
func (s *Service) Open() error {
	go s.serve()
	s.logger.Println("service listening on", s.tn.Addr())
	return nil
}
func (s *Service) Close() error {
	s.tn.Close()
	return nil
}
func (s *Service) Addr() string {
	return s.addr.String()
}
func (s *Service) EnableHTTPS(b bool) {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.https = b
}
func (s *Service) SetAPIAddr(addr string) {
	s.mu.Lock()
	defer s.mu.Unlock()
	s.apiAddr = addr
}
func (s *Service) GetAPIAddr() string {
	s.mu.RLock()
	defer s.mu.RUnlock()
	return s.apiAddr
}