本文整理汇总了Golang中code/google/com/p/gogoprotobuf/proto.Bool函数的典型用法代码示例。如果您正苦于以下问题:Golang Bool函数的具体用法?Golang Bool怎么用?Golang Bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bool函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Stop
func (c *Connection) Stop(handle string, background, kill bool) (*warden.StopResponse, error) {
res, err := c.RoundTrip(
&warden.StopRequest{
Handle: proto.String(handle),
Background: proto.Bool(background),
Kill: proto.Bool(kill),
},
&warden.StopResponse{},
)
if err != nil {
return nil, err
}
return res.(*warden.StopResponse), nil
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:16,代码来源:connection.go
示例2: newTestMessage
func newTestMessage() *pb.MyMessage {
msg := &pb.MyMessage{
Count: proto.Int32(42),
Name: proto.String("Dave"),
Quote: proto.String(`"I didn't want to go."`),
Pet: []string{"bunny", "kitty", "horsey"},
Inner: &pb.InnerMessage{
Host: proto.String("footrest.syd"),
Port: proto.Int32(7001),
Connected: proto.Bool(true),
},
Others: []*pb.OtherMessage{
{
Key: proto.Int64(0xdeadbeef),
Value: []byte{1, 65, 7, 12},
},
{
Weight: proto.Float32(6.022),
Inner: &pb.InnerMessage{
Host: proto.String("lesha.mtv"),
Port: proto.Int32(8002),
},
},
},
Bikeshed: pb.MyMessage_BLUE.Enum(),
Somegroup: &pb.MyMessage_SomeGroup{
GroupField: proto.Int32(8),
},
// One normally wouldn't do this.
// This is an undeclared tag 13, as a varint (wire type 0) with value 4.
XXX_unrecognized: []byte{13<<3 | 0, 4},
}
ext := &pb.Ext{
Data: proto.String("Big gobs for big rats"),
}
if err := proto.SetExtension(msg, pb.E_Ext_More, ext); err != nil {
panic(err)
}
greetings := []string{"adg", "easy", "cow"}
if err := proto.SetExtension(msg, pb.E_Greeting, greetings); err != nil {
panic(err)
}
// Add an unknown extension. We marshal a pb.Ext, and fake the ID.
b, err := proto.Marshal(&pb.Ext{Data: proto.String("3G skiing")})
if err != nil {
panic(err)
}
b = append(proto.EncodeVarint(201<<3|proto.WireBytes), b...)
proto.SetRawExtension(msg, 201, b)
// Extensions can be plain fields, too, so let's test that.
b = append(proto.EncodeVarint(202<<3|proto.WireVarint), 19)
proto.SetRawExtension(msg, 202, b)
return msg
}
开发者ID:hail100,项目名称:cli,代码行数:57,代码来源:text_test.go
示例3: Encode
// Encodes the SnapshotResponse to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (resp *SnapshotResponse) Encode(w io.Writer) (int, error) {
pb := &protobuf.SnapshotResponse{
Success: proto.Bool(resp.Success),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
}
开发者ID:newsky,项目名称:raft,代码行数:13,代码来源:snapshot.go
示例4: newAppendEntriesResponse
// Creates a new AppendEntries response.
func newAppendEntriesResponse(term uint64, success bool, index uint64, commitIndex uint64) *AppendEntriesResponse {
pb := &protobuf.AppendEntriesResponse{
Term: proto.Uint64(term),
Index: proto.Uint64(index),
Success: proto.Bool(success),
CommitIndex: proto.Uint64(commitIndex),
}
return &AppendEntriesResponse{
pb: pb,
}
}
开发者ID:RubanDeventhiran,项目名称:raft,代码行数:13,代码来源:append_entries.go
示例5: Encode
// Encodes the RequestVoteResponse to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (resp *RequestVoteResponse) Encode(w io.Writer) (int, error) {
pb := &protobuf.RequestVoteResponse{
Term: proto.Uint64(resp.Term),
VoteGranted: proto.Bool(resp.VoteGranted),
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
}
开发者ID:ptsolmyr,项目名称:raft,代码行数:15,代码来源:request_vote_response.go
示例6: Spawn
func (c *Connection) Spawn(handle, script string, discardOutput bool) (*warden.SpawnResponse, error) {
res, err := c.RoundTrip(
&warden.SpawnRequest{
Handle: proto.String(handle),
Script: proto.String(script),
DiscardOutput: proto.Bool(discardOutput),
},
&warden.SpawnResponse{},
)
if err != nil {
return nil, err
}
return res.(*warden.SpawnResponse), nil
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:16,代码来源:connection.go
示例7: streamStreamIn
func streamStreamIn(conn connection.Connection) {
for {
buf := make([]byte, 64*1024)
n, err := os.Stdin.Read(buf)
if n > 0 {
err := conn.SendMessage(&warden.StreamChunk{
Content: buf[:n],
})
if err != nil {
fmt.Println("writing content failed:", err)
os.Exit(1)
}
}
if err == io.EOF {
err := conn.SendMessage(&warden.StreamChunk{
EOF: proto.Bool(true),
})
if err != nil {
fmt.Println("writing EOF failed:", err)
os.Exit(1)
}
break
}
if err != nil {
fmt.Println("stream interrupted:", err)
os.Exit(1)
}
}
resp := &warden.StreamInResponse{}
err := conn.ReadResponse(resp)
if err != nil {
fmt.Println("stream failed:", err)
os.Exit(1)
}
}
开发者ID:pivotal-cf-experimental,项目名称:shank,代码行数:41,代码来源:main.go
示例8:
})
Describe("Stopping", func() {
BeforeEach(func() {
wardenMessages = append(wardenMessages,
&protocol.StopResponse{},
)
})
It("should stop the container", func() {
err := connection.Stop("foo", true, true)
Ω(err).ShouldNot(HaveOccurred())
assertWriteBufferContains(&protocol.StopRequest{
Handle: proto.String("foo"),
Background: proto.Bool(true),
Kill: proto.Bool(true),
})
})
})
Describe("Destroying", func() {
BeforeEach(func() {
wardenMessages = append(wardenMessages,
&protocol.DestroyResponse{},
)
})
It("should stop the container", func() {
err := connection.Destroy("foo")
Ω(err).ShouldNot(HaveOccurred())
开发者ID:vito,项目名称:warden-linux,代码行数:31,代码来源:connection_test.go
示例9: init
import (
"testing"
"code.google.com/p/gogoprotobuf/proto"
pb "./testdata"
)
var cloneTestMessage = &pb.MyMessage{
Count: proto.Int32(42),
Name: proto.String("Dave"),
Pet: []string{"bunny", "kitty", "horsey"},
Inner: &pb.InnerMessage{
Host: proto.String("niles"),
Port: proto.Int32(9099),
Connected: proto.Bool(true),
},
Others: []*pb.OtherMessage{
{
Value: []byte("some bytes"),
},
},
Somegroup: &pb.MyMessage_SomeGroup{
GroupField: proto.Int32(6),
},
RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
}
func init() {
ext := &pb.Ext{
Data: proto.String("extension"),
开发者ID:hail100,项目名称:cli,代码行数:31,代码来源:clone_test.go
示例10: findHandler
//.........这里部分代码省略.........
var newglobs []string
for _, glob := range globs {
lbrace := strings.Index(glob, "{")
rbrace := -1
if lbrace > -1 {
rbrace = strings.Index(glob[lbrace:], "}")
if rbrace > -1 {
rbrace += lbrace
}
}
if lbrace > -1 && rbrace > -1 {
bracematch = true
expansion := glob[lbrace+1 : rbrace]
parts := strings.Split(expansion, ",")
for _, sub := range parts {
if len(newglobs) > config.MaxGlobs {
break
}
newglobs = append(newglobs, glob[:lbrace]+sub+glob[rbrace+1:])
}
} else {
if len(newglobs) > config.MaxGlobs {
break
}
newglobs = append(newglobs, glob)
}
}
globs = newglobs
if !bracematch {
break
}
}
var files []string
for _, glob := range globs {
nfiles, err := filepath.Glob(config.WhisperData + "/" + glob)
if err == nil {
files = append(files, nfiles...)
}
}
leafs := make([]bool, len(files))
for i, p := range files {
p = p[len(config.WhisperData+"/"):]
if strings.HasSuffix(p, ".wsp") {
p = p[:len(p)-4]
leafs[i] = true
} else {
leafs[i] = false
}
files[i] = strings.Replace(p, "/", ".", -1)
}
if format == "json" || format == "protobuf" {
name := req.FormValue("query")
response := pb.GlobResponse{
Name: &name,
Matches: make([]*pb.GlobMatch, 0),
}
for i, p := range files {
response.Matches = append(response.Matches, &pb.GlobMatch{Path: proto.String(p), IsLeaf: proto.Bool(leafs[i])})
}
var b []byte
var err error
switch format {
case "json":
b, err = json.Marshal(response)
case "protobuf":
b, err = proto.Marshal(&response)
}
if err != nil {
Metrics.FindErrors.Add(1)
log.Errorf("failed to create %s data for glob %s: %s",
format, *response.Name, err)
return
}
wr.Write(b)
} else if format == "pickle" {
// [{'metric_path': 'metric', 'intervals': [(x,y)], 'isLeaf': True},]
var metrics []map[string]interface{}
var m map[string]interface{}
for i, p := range files {
m = make(map[string]interface{})
m["metric_path"] = p
// m["intervals"] = dunno how to do a tuple here
m["isLeaf"] = leafs[i]
metrics = append(metrics, m)
}
wr.Header().Set("Content-Type", "application/pickle")
pEnc := pickle.NewEncoder(wr)
pEnc.Encode(metrics)
}
log.Infof("find: %d hits for %s", len(files), req.FormValue("query"))
return
}
开发者ID:rmoorman,项目名称:carbonserver,代码行数:101,代码来源:main.go
示例11:
It("should be able to create, stop and destroy a container", func() {
res, err := client.Create()
Ω(err).ShouldNot(HaveOccurred())
Ω(res.GetHandle()).Should(Equal("foo"))
_, err = client.Stop("foo", true, true)
Ω(err).ShouldNot(HaveOccurred())
_, err = client.Destroy("foo")
Ω(err).ShouldNot(HaveOccurred())
expectedWriteBufferContents := string(warden.Messages(
&warden.CreateRequest{},
&warden.StopRequest{
Handle: proto.String("foo"),
Background: proto.Bool(true),
Kill: proto.Bool(true),
},
&warden.DestroyRequest{Handle: proto.String("foo")},
).Bytes())
Ω(string(writeBuffer.Bytes())).Should(Equal(expectedWriteBufferContents))
})
})
Describe("Spawning and streaming", func() {
BeforeEach(func() {
provider = NewFakeConnectionProvider(
warden.Messages(
&warden.SpawnResponse{
JobId: proto.Uint32(42),
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:31,代码来源:client_test.go
注:本文中的code/google/com/p/gogoprotobuf/proto.Bool函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论