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: server.go
    path of file: ./repos/seaweedfs/weed/command
    
    the code of the file until where you have to start completion: package command

import (
	"fmt"
	"net/http"
	"os"
	"strings"
	"time"

	stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"

	"github.com/seaweedfs/seaweedfs/weed/glog"
	"github.com/seaweedfs/seaweedfs/weed/pb"
	"github.com/seaweedfs/seaweedfs/weed/util"
	"github.com/seaweedfs/seaweedfs/weed/util/grace"
)

type ServerOptions struct {
	cpuprofile *string
	memprofile *string
	debug      *bool
	debugPort  *int
	v          VolumeServerOptions
}

var (
	serverOptions   ServerOptions
	masterOptions   MasterOptions
	filerOptions    FilerOptions
	s3Options       S3Options
	iamOptions      IamOptions
	webdavOptions   WebDavOption
	mqBrokerOptions MessageQueueBrokerOptions
)

func init() {
	cmdServer.Run = runServer // break init cycle
}

var cmdServer = &Command{
	UsageLine: "server -dir=/tmp -volume.max=5 -ip=server_name",
	Short:     "start a master server, a volume server, and optionally a filer and a S3 gateway",
	Long: `start both a volume server to provide storage spaces
  and a master server to provide volume=>location mapping service and sequence number of file ids

  This is provided as a convenient way to start both volume server and master server.
  The servers acts exactly the same as starting them separately.
  So other volume servers can connect to this master server also.

  Optionally, a filer server can be started.
  Also optionally, a S3 gateway can be started.

  `,
}

var (
	serverIp                  = cmdServer.Flag.String("ip", util.DetectedHostAddress(), "ip or server name, also used as identifier")
	serverBindIp              = cmdServer.Flag.String("ip.bind", "", "ip address to bind to. If empty, default to same as -ip option.")
	serverTimeout             = cmdServer.Flag.Int("idleTimeout", 30, "connection idle seconds")
	serverDataCenter          = cmdServer.Flag.String("dataCenter", "", "current volume server's data center name")
	serverRack                = cmdServer.Flag.String("rack", "", "current volume server's rack name")
	serverWhiteListOption     = cmdServer.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.")
	serverDisableHttp         = cmdServer.Flag.Bool("disableHttp", false, "disable http requests, only gRPC operations are allowed.")
	volumeDataFolders         = cmdServer.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...")
	volumeMaxDataVolumeCounts = cmdServer.Flag.String("volume.max", "8", "maximum numbers of volumes, count[,count]... If set to zero, the limit will be auto configured as free disk space divided by volume size.")
	volumeMinFreeSpacePercent = cmdServer.Flag.String("volume.minFreeSpacePercent", "1", "minimum free disk space (default to 1%). Low disk space will mark all volumes as ReadOnly (deprecated, use minFreeSpace instead).")
	volumeMinFreeSpace        = cmdServer.Flag.String("volume.minFreeSpace", "", "min free disk space (value<=100 as percentage like 1, other as human readable bytes, like 10GiB). Low disk space will mark all volumes as ReadOnly.")
	serverMetricsHttpPort     = cmdServer.Flag.Int("metricsPort", 0, "Prometheus metrics listen port")

	// pulseSeconds              = cmdServer.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
	isStartingMaster
    
func runServer(cmd *Command, args []string) bool {

	if *serverOptions.debug {
		go http.ListenAndServe(fmt.Sprintf(":%d", *serverOptions.debugPort), nil)
	}

	util.LoadConfiguration("security", false)
	util.LoadConfiguration("master", false)

	grace.SetupProfiling(*serverOptions.cpuprofile, *serverOptions.memprofile)

	if *isStartingS3 {
		*isStartingFiler = true
	}
	if *isStartingIam {
		*isStartingFiler = true
	}
	if *isStartingWebDav {
		*isStartingFiler = true
	}
	if *isStartingMqBroker {
		*isStartingFiler = true
	}

	if *isStartingMasterServer {
		_, peerList := checkPeers(*serverIp, *masterOptions.port, *masterOptions.portGrpc, *masterOptions.peers)
		peers := strings.Join(pb.ToAddressStrings(peerList), ",")
		masterOptions.peers = &peers
	}

	if *serverBindIp == "" {
		serverBindIp = serverIp
	}

	// ip address
	masterOptions.ip = serverIp
	masterOptions.ipBind = serverBindIp
	filerOptions.masters = pb.ServerAddresses(*masterOptions.peers).ToServiceDiscovery()
	filerOptions.ip = serverIp
	filerOptions.bindIp = serverBindIp
	s3Options.bindIp = serverBindIp
	iamOptions.ip = serverBindIp
	iamOptions.masters = masterOptions.peers
	serverOptions.v.ip = serverIp
	serverOptions.v.bindIp = serverBindIp
	serverOptions.v.masters = pb.ServerAddresses(*masterOptions.peers).ToAddresses()
	serverOptions.v.idleConnectionTimeout = serverTimeout
	serverOptions.v.dataCenter = serverDataCenter
	serverOptions.v.rack = serverRack
	mqBrokerOptions.ip = serverIp
	mqBrokerOptions.masters = filerOptions.masters.GetInstancesAsMap()
	mqBrokerOptions.filerGroup = filerOptions.filerGroup

	// serverOptions.v.pulseSeconds = pulseSeconds
	// masterOptions.pulseSeconds = pulseSeconds

	masterOptions.whiteList = serverWhiteListOption

	filerOptions.dataCenter = serverDataCenter
	filerOptions.rack = serverRack
	mqBrokerOptions.dataCenter = serverDataCenter
	mqBrokerOptions.rack = serverRack
	s3Options.dataCenter = serverDataCenter
	filerOptions.disableHttp = serverDisableHttp
	masterOptions.disableHttp = serverDisableHttp

	filerAddress := string(pb.NewServerAddress(*serverIp, *filerOptions.port, *filerOptions.portGrpc))
	s3Options.filer = &filerAddress
	iamOptions.filer = &filerAddress
	webdavOptions.filer = &filerAddress
	mqBrokerOptions.filerGroup = filerOptions.filerGroup

	go stats_collect.StartMetricsServer(*serverBindIp, *serverMetricsHttpPort)

	folders := strings.Split(*volumeDataFolders, ",")

	if *masterOptions.volumeSizeLimitMB > util.VolumeSizeLimitGB*1000 {
		glog.Fatalf("masterVolumeSizeLimitMB should be less than 30000")
	}

	if *masterOptions.metaFolder == "" {
		*masterOptions.metaFolder = folders[0]
	}
	if err := util.TestFolderWritable(util.ResolvePath(*masterOptions.metaFolder)); err != nil {
		glog.Fatalf("Check Meta Folder (-mdir=\"%s\") Writable: %s", *masterOptions.metaFolder, err)
	}
	filerOptions.defaultLevelDbDirectory = masterOptions.metaFolder

	serverWhiteList := util.StringSplit(*serverWhiteListOption, ",")

	if *isStartingFiler {
		if *filerOptions.diskType == "" && *serverOptions.v.diskType != "" {
			filerOptions.diskType = serverOptions.v.diskType
		}
		go func() {
			time.Sleep(1 * time.Second)
			filerOptions.startFiler()
		}()
	}

	if *isStartingS3 {
		go func() {
			time.Sleep(2 * time.Second)
			s3Options.localFilerSocket = filerOptions.localSocket
			s3Options.startS3Server()
		}()
	}

	if *isStartingIam {
		go func() {
			time.Sleep(2 * time.Second)
			iamOptions.startIamServer()
		}()
	}

	if *isStartingWebDav {
		go func() {
			time.Sleep(2 * time.Second)
			webdavOptions.startWebDav()

		}()
	}

	if *isStartingMqBroker {
		go func() {
			time.Sleep(2 * time.Second)
			mqBrokerOptions.startQueueServer()
		}()
	}

	// start volume server
	if *isStartingVolumeServer {
		minFreeSpaces := util.MustParseMinFreeSpace(*volumeMinFreeSpace, *volumeMinFreeSpacePercent)
		go serverOptions.v.startVolumeServer(*volumeDataFolders, *volumeMaxDataVolumeCounts, *serverWhiteListOption, minFreeSpaces)
	}

	if *isStartingMasterServer {
		go startMaster(masterOptions, serverWhiteList)
	}

	select {}
}