當前位置: 首頁>>代碼示例>>Golang>>正文


Golang netutil.FullyQualifiedHostnameOrPanic函數代碼示例

本文整理匯總了Golang中github.com/youtube/vitess/go/netutil.FullyQualifiedHostnameOrPanic函數的典型用法代碼示例。如果您正苦於以下問題:Golang FullyQualifiedHostnameOrPanic函數的具體用法?Golang FullyQualifiedHostnameOrPanic怎麽用?Golang FullyQualifiedHostnameOrPanic使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了FullyQualifiedHostnameOrPanic函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	defer exit.Recover()
	defer logutil.Flush()

	zknsDomain := flag.String("zkns-domain", "", "The naming hierarchy portion to serve")
	zknsRoot := flag.String("zkns-root", "", "The root path from which to resolve")
	bindAddr := flag.String("bind-addr", ":31981", "Bind the debug http server")
	flag.Parse()

	if *bindAddr != "" {
		go func() {
			err := http.ListenAndServe(*bindAddr, nil)
			if err != nil {
				log.Errorf("ListenAndServe: %s", err)
				exit.Return(1)
			}
		}()
	}

	zconn := zk.NewMetaConn()
	fqdn := netutil.FullyQualifiedHostnameOrPanic()
	zr1 := newZknsResolver(zconn, fqdn, *zknsDomain, *zknsRoot)
	pd := &pdns{zr1}
	pd.Serve(os.Stdin, os.Stdout)
	os.Stdout.Close()
}
開發者ID:pranjal5215,項目名稱:vitess,代碼行數:26,代碼來源:pdns.go

示例2: MakeZkConfigFromString

/*
  Create a config for this instance.

  <server_id>@<hostname>:<leader_port>:<election_port>:<client_port>

  If server_id > 1000, then we assume this is a global quorum.
  server_id's must be 1-255, global id's are 1001-1255 mod 1000.
*/
func MakeZkConfigFromString(cmdLine string, myId uint32) *ZkConfig {
	zkConfig := NewZkConfig()
	for _, zki := range strings.Split(cmdLine, ",") {
		zkiParts := strings.SplitN(zki, "@", 2)
		if len(zkiParts) != 2 {
			panic("bad command line format for zk config")
		}
		zkId := zkiParts[0]
		zkAddrParts := strings.Split(zkiParts[1], ":")
		serverId, _ := strconv.ParseUint(zkId, 10, 0)
		if serverId > 1000 {
			serverId = serverId % 1000
			zkConfig.Global = true
		}
		myId = myId % 1000

		zkServer := zkServerAddr{ServerId: uint32(serverId), ClientPort: 2181,
			LeaderPort: 2888, ElectionPort: 3888}
		switch len(zkAddrParts) {
		case 4:
			zkServer.ClientPort, _ = strconv.Atoi(zkAddrParts[3])
			fallthrough
		case 3:
			zkServer.ElectionPort, _ = strconv.Atoi(zkAddrParts[2])
			fallthrough
		case 2:
			zkServer.LeaderPort, _ = strconv.Atoi(zkAddrParts[1])
			fallthrough
		case 1:
			zkServer.Hostname = zkAddrParts[0]
			// if !strings.Contains(zkServer.Hostname, ".") {
			// 	panic(fmt.Errorf("expected fully qualified hostname: %v", zkServer.Hostname))
			// }
		default:
			panic(fmt.Errorf("bad command line format for zk config"))
		}
		zkConfig.Servers = append(zkConfig.Servers, zkServer)
	}
	hostname := netutil.FullyQualifiedHostnameOrPanic()
	log.Infof("Fully qualified machine hostname was detected as: %v", hostname)
	for _, zkServer := range zkConfig.Servers {
		if (myId > 0 && myId == zkServer.ServerId) || (myId == 0 && zkServer.Hostname == hostname) {
			zkConfig.ServerId = zkServer.ServerId
			zkConfig.ClientPort = zkServer.ClientPort
			break
		}
	}
	if zkConfig.ServerId == 0 {
		panic(fmt.Errorf("no zk server found for host %v in config %v", hostname, cmdLine))
	}
	return zkConfig
}
開發者ID:CowLeo,項目名稱:vitess,代碼行數:60,代碼來源:zkconf.go

示例3: Addr

// Addr returns the fully qualified host name + port for this instance.
func (mysqld *Mysqld) Addr() string {
	hostname := netutil.FullyQualifiedHostnameOrPanic()
	return netutil.JoinHostPort(hostname, int32(mysqld.config.MysqlPort))
}
開發者ID:springlee,項目名稱:vitess,代碼行數:5,代碼來源:mysqld.go

示例4: Addr

func (mysqld *Mysqld) Addr() string {
	hostname := netutil.FullyQualifiedHostnameOrPanic()
	return fmt.Sprintf("%v:%v", hostname, mysqld.config.MysqlPort)
}
開發者ID:rjammala,項目名稱:vitess,代碼行數:4,代碼來源:mysqld.go

示例5:

"Entries": [
  {
    "host": "test1"
  }
]}`

	fakeA = `{
"Entries": [
  {
    "host": "test1",
    "ipv4": "0.0.0.1"
  }
]}`
)

var fqdn = netutil.FullyQualifiedHostnameOrPanic()

var zconn = &TestZkConn{map[string]string{
	"/zk/test/zkns/srv":   fakeSRV,
	"/zk/test/zkns/cname": fakeCNAME,
	"/zk/test/zkns/a":     fakeA,
}}

var queries = []string{
	"Q\t_http.srv.zkns.test.zk\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
	"Q\ta.zkns.test.zk\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
	"Q\tcname.zkns.test.zk\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
	"Q\tempty.zkns.test.zk\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
	"Q\bad.domain\tIN\tANY\t-1\t1.1.1.1\t1.1.1.2",
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:30,代碼來源:pdns_test.go


注:本文中的github.com/youtube/vitess/go/netutil.FullyQualifiedHostnameOrPanic函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。