本文整理匯總了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
}
示例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
}
示例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
}