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


Golang model.ServiceUpdate類代碼示例

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


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

示例1: startRejecting

func (svc *service) startRejecting(upd model.ServiceUpdate) (serviceState, error) {
	rule := []interface{}{
		"-p", "tcp",
		"-d", upd.IP(),
		"--dport", upd.Port,
		"-j", "REJECT",
	}

	err := svc.config.addRule("filter", rule)
	if err != nil {
		return nil, err
	}

	return rejecting(func() {
		svc.config.deleteRule("filter", rule)
	}), nil
}
開發者ID:squaremo,項目名稱:ambergris,代碼行數:17,代碼來源:daemon.go

示例2: doRequest

func (srv *Server) doRequest(conn *net.UnixConn) error {
	var buf bytes.Buffer
	_, err := io.Copy(&buf, conn)
	if err != nil {
		return err
	}

	// XXX support service deletion commands

	parts := strings.Split(strings.TrimSpace(buf.String()), " ")
	if len(parts) <= 0 {
		return fmt.Errorf("service specification should begin with port:ip-address")
	}

	addr, err := net.ResolveTCPAddr("tcp", parts[0])
	if err != nil {
		return err
	}

	var insts []model.Instance
	for _, inst := range parts[2:] {
		addr, err := net.ResolveTCPAddr("tcp", inst)
		if err != nil {
			return err
		}

		insts = append(insts, model.MakeInstance(addr.IP, addr.Port))
	}

	var update model.ServiceUpdate
	update.ServiceKey = model.MakeServiceKey("tcp", addr.IP, addr.Port)
	update.ServiceInfo = &model.ServiceInfo{
		Protocol:  parts[1],
		Instances: insts,
	}

	select {
	case srv.updates <- update:
	case <-srv.closed:
	}

	return nil
}
開發者ID:bboreham,項目名稱:ambergris,代碼行數:43,代碼來源:server.go

示例3: startForwarding

func (svc *service) startForwarding(upd model.ServiceUpdate) (serviceState, error) {
	bridgeIP, err := svc.config.bridgeIP()
	if err != nil {
		return nil, err
	}

	listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: bridgeIP})
	if err != nil {
		return nil, err
	}

	success := false
	defer func() {
		if !success {
			listener.Close()
		}
	}()

	rule := []interface{}{
		"-p", "tcp",
		"-d", upd.IP(),
		"--dport", upd.Port,
		"-j", "DNAT",
		"--to-destination", listener.Addr(),
	}
	err = svc.config.addRule("nat", rule)
	if err != nil {
		return nil, err
	}

	fwd := &forwarding{
		service:     svc,
		rule:        rule,
		listener:    listener,
		stopCh:      make(chan struct{}),
		ServiceInfo: upd.ServiceInfo,
	}

	fwd.chooseShim()
	go fwd.run()
	success = true
	return fwd, nil
}
開發者ID:squaremo,項目名稱:ambergris,代碼行數:43,代碼來源:forward.go


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