当前位置: 首页>>代码示例>>Golang>>正文


Golang Properties.Features方法代码示例

本文整理汇总了Golang中github.com/skriptble/nine/stream.Properties.Features方法的典型用法代码示例。如果您正苦于以下问题:Golang Properties.Features方法的具体用法?Golang Properties.Features怎么用?Golang Properties.Features使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/skriptble/nine/stream.Properties的用法示例。


在下文中一共展示了Properties.Features方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: HandleFeature

func (sh SessionHandler) HandleFeature(props stream.Properties) stream.Properties {
	if props.Status&stream.Bind != 0 || props.Status&stream.Auth == 0 {
		return props
	}

	props.Features = append(props.Features, element.Session)
	return props
}
开发者ID:skriptble,项目名称:nine,代码行数:8,代码来源:session.go

示例2: GenerateFeature

func (h Handler) GenerateFeature(props stream.Properties) stream.Properties {
	if props.Status&stream.Bind != 0 || props.Status&stream.Auth == 0 {
		return props
	}

	props.Features = append(props.Features, element.Bind)
	return props
}
开发者ID:skriptble,项目名称:nine,代码行数:8,代码来源:handler.go

示例3: TestStartReceiving


//.........这里部分代码省略.........
		_, err := pipe2.Write(hdr.WriteBytes())
		if err != nil {
			t.Errorf("Unexpected error while writing to pipe2: %s", err)
		}
		err = pipe2.Close()
		if err != nil {
			t.Errorf("Unexpected error while closing pipe2: %s", err)
		}
	}()
	gotProps, err = tcpTsp.Start(props)
	if err != io.ErrClosedPipe {
		t.Error("Should return error from writing header to the underlying connection.")
		t.Errorf("\nWant:%s\nGot :%s", io.ErrClosedPipe, err)
	}

	// Should set the To field to the properties To field if it is set
	props.To = "[email protected]"

	// Should overwrite stream features if there is a tls config and the stream
	// is not yet secure
	pipe1, pipe2 = net.Pipe()
	tcpTsp = NewTCP(pipe1, stream.Receiving, &tls.Config{}, true)
	go func() {
		hdr := stream.Header{To: "localhost", From: "[email protected]"}
		_, err := pipe2.Write(hdr.WriteBytes())
		if err != nil {
			t.Errorf("Unexpected error while writing to pipe2: %s", err)
		}
		// Doing two tests at the same time, because they are orthogonal
		hdr.To, hdr.From = "[email protected]", "localhost"
		want = hdr.WriteBytes()
		// We need to add an extra 36 bytes for the id length
		hdrLen := len(want) + 36
		ftrs := element.StreamFeatures.AddChild(
			element.StartTLS.AddChild(
				element.Required),
		)
		want = append(want, ftrs.WriteBytes()...)
		// We need to add an extra 36 bytes for the id length
		got = make([]byte, len(want)+36)
		_, err = pipe2.Read(got)
		if err != nil {
			t.Errorf("Unexpected error while reading from pipe2: %s", err)
		}
		_, err = pipe2.Read(got[hdrLen:])
		if err != nil {
			t.Errorf("Unexpected error while reading from pipe2: %s", err)
		}
	}()
	gotProps, err = tcpTsp.Start(props)
	if err != nil {
		t.Errorf("Unexpected error from Start: %s", err)
	}
	// Need to remove stream ID before comparing
	idx = bytes.Index(got, []byte("id='"))
	if idx == -1 {
		t.Error("Received stream is missing id attribute")
	}
	// We slice the id out of the received stream header.
	got = append(got[:idx+4], got[idx+40:]...)
	if !bytes.Equal(want, got) {
		t.Error("Should overwrite stream features if there is a tls config and the stream is not yet secure.")
		t.Errorf("\nWant:%s\nGot :%s", want, got)
	}

	// Should be able to start stream
开发者ID:skriptble,项目名称:nine,代码行数:67,代码来源:tcp_test.go


注:本文中的github.com/skriptble/nine/stream.Properties.Features方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。