本文整理汇总了Golang中code/google/com/p/gogoprotobuf/proto.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了String函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewHttpStart
func NewHttpStart(req *http.Request, peerType events.PeerType, requestId *uuid.UUID) *events.HttpStart {
httpStart := &events.HttpStart{
Timestamp: proto.Int64(time.Now().UnixNano()),
RequestId: NewUUID(requestId),
PeerType: &peerType,
Method: events.HttpStart_Method(events.HttpStart_Method_value[req.Method]).Enum(),
Uri: proto.String(fmt.Sprintf("%s%s", req.Host, req.URL.Path)),
RemoteAddress: proto.String(req.RemoteAddr),
UserAgent: proto.String(req.UserAgent()),
}
if applicationId, err := uuid.ParseHex(req.Header.Get("X-CF-ApplicationID")); err == nil {
httpStart.ApplicationId = NewUUID(applicationId)
}
if instanceIndex, err := strconv.Atoi(req.Header.Get("X-CF-InstanceIndex")); err == nil {
httpStart.InstanceIndex = proto.Int(instanceIndex)
}
if instanceId := req.Header.Get("X-CF-InstanceID"); instanceId != "" {
httpStart.InstanceId = &instanceId
}
return httpStart
}
开发者ID:KeyOfSpectator,项目名称:gorouter,代码行数:25,代码来源:factories.go
示例2: isAuthorized
func (proxy *Proxy) isAuthorized(appId, authToken string, clientAddress string) (bool, *logmessage.LogMessage) {
newLogMessage := func(message []byte) *logmessage.LogMessage {
currentTime := time.Now()
messageType := logmessage.LogMessage_ERR
return &logmessage.LogMessage{
Message: message,
AppId: proto.String(appId),
MessageType: &messageType,
SourceName: proto.String("LGR"),
Timestamp: proto.Int64(currentTime.UnixNano()),
}
}
if appId == "" {
message := fmt.Sprintf("HttpServer: Did not accept sink connection with invalid app id: %s.", clientAddress)
proxy.logger.Warn(message)
return false, newLogMessage([]byte("Error: Invalid target"))
}
if authToken == "" {
message := fmt.Sprintf("HttpServer: Did not accept sink connection from %s without authorization.", clientAddress)
proxy.logger.Warnf(message)
return false, newLogMessage([]byte("Error: Authorization not provided"))
}
if !proxy.authorize(authToken, appId, proxy.logger) {
message := fmt.Sprintf("HttpServer: Auth token [%s] not authorized to access appId [%s].", authToken, appId)
proxy.logger.Warn(message)
return false, newLogMessage([]byte("Error: Invalid authorization"))
}
return true, nil
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:34,代码来源:output_proxy.go
示例3: Encode
// Encodes the SnapshotRecoveryRequest to a buffer. Returns the number of bytes
// written and any error that may have occurred.
func (req *SnapshotRecoveryRequest) Encode(w io.Writer) (int, error) {
protoPeers := make([]*protobuf.SnapshotRecoveryRequest_Peer, len(req.Peers))
for i, peer := range req.Peers {
protoPeers[i] = &protobuf.SnapshotRecoveryRequest_Peer{
Name: proto.String(peer.Name),
ConnectionString: proto.String(peer.ConnectionString),
}
}
pb := &protobuf.SnapshotRecoveryRequest{
LeaderName: proto.String(req.LeaderName),
LastIndex: proto.Uint64(req.LastIndex),
LastTerm: proto.Uint64(req.LastTerm),
Peers: protoPeers,
State: req.State,
}
p, err := proto.Marshal(pb)
if err != nil {
return -1, err
}
return w.Write(p)
}
开发者ID:newsky,项目名称:raft,代码行数:27,代码来源:snapshot.go
示例4: NewNoaaLogMessage
func NewNoaaLogMessage(msgText, appGuid, sourceName string, timestamp time.Time) *events.LogMessage {
messageType := events.LogMessage_ERR
return &events.LogMessage{
Message: []byte(msgText),
AppId: proto.String(appGuid),
MessageType: &messageType,
SourceType: proto.String(sourceName),
Timestamp: proto.Int64(timestamp.UnixNano()),
}
}
开发者ID:raghulsid,项目名称:cli,代码行数:11,代码来源:log_messages.go
示例5: NewLogMessageWithSourceName
func NewLogMessageWithSourceName(t *testing.T, messageString, sourceName, appId string) *LogMessage {
currentTime := time.Now()
messageType := LogMessage_OUT
protoMessage := &LogMessage{
Message: []byte(messageString),
AppId: proto.String(appId),
MessageType: &messageType,
Timestamp: proto.Int64(currentTime.UnixNano()),
SourceName: proto.String(sourceName),
}
return protoMessage
}
开发者ID:GABONIA,项目名称:cli,代码行数:13,代码来源:message_test.go
示例6: generateLogMessage
func generateLogMessage(messageString, appId string, messageType logmessage.LogMessage_MessageType, sourceName, sourceId string) *logmessage.LogMessage {
currentTime := time.Now()
logMessage := &logmessage.LogMessage{
Message: []byte(messageString),
AppId: proto.String(appId),
MessageType: &messageType,
SourceName: proto.String(sourceName),
SourceId: proto.String(sourceId),
Timestamp: proto.Int64(currentTime.UnixNano()),
}
return logMessage
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:13,代码来源:sinkserver_suite_test.go
示例7: startAppWithInstancesAndErrors
func startAppWithInstancesAndErrors(t *testing.T, app cf.Application, instances [][]cf.ApplicationInstance, errorCodes []string) (ui *testterm.FakeUI, appRepo *testapi.FakeApplicationRepository, reqFactory *testreq.FakeReqFactory) {
token, err := testconfig.CreateAccessTokenWithTokenInfo(configuration.TokenInfo{
Username: "my-user",
})
assert.NoError(t, err)
config := &configuration.Configuration{
Space: cf.Space{Name: "my-space"},
Organization: cf.Organization{Name: "my-org"},
AccessToken: token,
ApplicationStartTimeout: 2,
}
appRepo = &testapi.FakeApplicationRepository{
FindByNameApp: app,
GetInstancesResponses: instances,
GetInstancesErrorCodes: errorCodes,
}
currentTime := time.Now()
messageType := logmessage.LogMessage_ERR
sourceType := logmessage.LogMessage_DEA
logMessage1 := logmessage.LogMessage{
Message: []byte("Log Line 1"),
AppId: proto.String(app.Guid),
MessageType: &messageType,
SourceType: &sourceType,
Timestamp: proto.Int64(currentTime.UnixNano()),
}
logMessage2 := logmessage.LogMessage{
Message: []byte("Log Line 2"),
AppId: proto.String(app.Guid),
MessageType: &messageType,
SourceType: &sourceType,
Timestamp: proto.Int64(currentTime.UnixNano()),
}
logRepo := &testapi.FakeLogsRepository{
TailLogMessages: []logmessage.LogMessage{
logMessage1,
logMessage2,
},
}
args := []string{"my-app"}
reqFactory = &testreq.FakeReqFactory{Application: app}
ui = callStart(args, config, reqFactory, appRepo, logRepo)
return
}
开发者ID:jalateras,项目名称:cli,代码行数:50,代码来源:start_test.go
示例8: Run
func (c *Connection) Run(handle, script string) (*warden.RunResponse, error) {
res, err := c.RoundTrip(
&warden.RunRequest{
Handle: proto.String(handle),
Script: proto.String(script),
},
&warden.RunResponse{},
)
if err != nil {
return nil, err
}
return res.(*warden.RunResponse), nil
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:15,代码来源:connection.go
示例9: NewLogMessage
func NewLogMessage(msgText, appGuid, sourceName string, timestamp time.Time) (msg *logmessage.Message) {
messageType := logmessage.LogMessage_ERR
logMsg := logmessage.LogMessage{
Message: []byte(msgText),
AppId: proto.String(appGuid),
MessageType: &messageType,
SourceName: proto.String(sourceName),
Timestamp: proto.Int64(timestamp.UnixNano()),
}
data, _ := proto.Marshal(&logMsg)
msg, _ = logmessage.ParseMessage(data)
return
}
开发者ID:nsnt,项目名称:cli,代码行数:15,代码来源:helpers.go
示例10: Wrap
func Wrap(e events.Event, origin string) (*events.Envelope, error) {
if origin == "" {
return nil, errors.New("Event not emitted due to missing origin information")
}
envelope := &events.Envelope{Origin: proto.String(origin)}
switch e.(type) {
case *events.Heartbeat:
envelope.EventType = events.Envelope_Heartbeat.Enum()
envelope.Heartbeat = e.(*events.Heartbeat)
case *events.HttpStart:
envelope.EventType = events.Envelope_HttpStart.Enum()
envelope.HttpStart = e.(*events.HttpStart)
case *events.HttpStop:
envelope.EventType = events.Envelope_HttpStop.Enum()
envelope.HttpStop = e.(*events.HttpStop)
case *events.ValueMetric:
envelope.EventType = events.Envelope_ValueMetric.Enum()
envelope.ValueMetric = e.(*events.ValueMetric)
case *events.CounterEvent:
envelope.EventType = events.Envelope_CounterEvent.Enum()
envelope.CounterEvent = e.(*events.CounterEvent)
default:
return nil, errors.New("Cannot create envelope for unknown event type")
}
return envelope, nil
}
开发者ID:machinelion,项目名称:gorouter,代码行数:29,代码来源:event_formatter.go
示例11: Wrap
func Wrap(e events.Event, origin string) (*events.Envelope, error) {
if origin == "" {
return nil, ErrorMissingOrigin
}
envelope := &events.Envelope{Origin: proto.String(origin)}
switch e := e.(type) {
case *events.Heartbeat:
envelope.EventType = events.Envelope_Heartbeat.Enum()
envelope.Heartbeat = e
case *events.HttpStart:
envelope.EventType = events.Envelope_HttpStart.Enum()
envelope.HttpStart = e
case *events.HttpStop:
envelope.EventType = events.Envelope_HttpStop.Enum()
envelope.HttpStop = e
case *events.ValueMetric:
envelope.EventType = events.Envelope_ValueMetric.Enum()
envelope.ValueMetric = e
case *events.CounterEvent:
envelope.EventType = events.Envelope_CounterEvent.Enum()
envelope.CounterEvent = e
case *events.LogMessage:
envelope.EventType = events.Envelope_LogMessage.Enum()
envelope.LogMessage = e
default:
return nil, ErrorUnknownEventType
}
return envelope, nil
}
开发者ID:johannespetzold,项目名称:gorouter,代码行数:32,代码来源:event_formatter.go
示例12: streamProcessToConnection
func (s *WardenServer) streamProcessToConnection(processID uint32, stream <-chan warden.ProcessStream, conn net.Conn) proto.Message {
for payload := range stream {
if payload.ExitStatus != nil {
return &protocol.ProcessPayload{
ProcessId: proto.Uint32(processID),
ExitStatus: proto.Uint32(*payload.ExitStatus),
}
}
var payloadSource protocol.ProcessPayload_Source
switch payload.Source {
case warden.ProcessStreamSourceStdout:
payloadSource = protocol.ProcessPayload_stdout
case warden.ProcessStreamSourceStderr:
payloadSource = protocol.ProcessPayload_stderr
case warden.ProcessStreamSourceStdin:
payloadSource = protocol.ProcessPayload_stdin
}
protocol.Messages(&protocol.ProcessPayload{
ProcessId: proto.Uint32(processID),
Source: &payloadSource,
Data: proto.String(string(payload.Data)),
}).WriteTo(conn)
}
return nil
}
开发者ID:vito,项目名称:warden-docker,代码行数:29,代码来源:request_handling.go
示例13: 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
示例14: newLogEntry
// Creates a new log entry associated with a log.
func newLogEntry(log *Log, event *ev, index uint64, term uint64, command Command) (*LogEntry, error) {
var buf bytes.Buffer
var commandName string
if command != nil {
commandName = command.CommandName()
if encoder, ok := command.(CommandEncoder); ok {
if err := encoder.Encode(&buf); err != nil {
return nil, err
}
} else {
json.NewEncoder(&buf).Encode(command)
}
}
pb := &protobuf.LogEntry{
Index: proto.Uint64(index),
Term: proto.Uint64(term),
CommandName: proto.String(commandName),
Command: buf.Bytes(),
}
e := &LogEntry{
pb: pb,
log: log,
event: event,
}
return e, nil
}
开发者ID:vinzenz,项目名称:stripe-ctf3-solutions,代码行数:30,代码来源:log_entry.go
示例15: TestLogsTailsTheAppLogs
func TestLogsTailsTheAppLogs(t *testing.T) {
app := cf.Application{Name: "my-app", Guid: "my-app-guid"}
currentTime := time.Now()
messageType := logmessage.LogMessage_ERR
deaSourceType := logmessage.LogMessage_DEA
deaSourceId := "42"
deaLogMessage := logmessage.LogMessage{
Message: []byte("Log Line 1"),
AppId: proto.String("my-app"),
MessageType: &messageType,
SourceType: &deaSourceType,
SourceId: &deaSourceId,
Timestamp: proto.Int64(currentTime.UnixNano()),
}
logs := []logmessage.LogMessage{deaLogMessage}
reqFactory, logsRepo := getLogsDependencies()
reqFactory.Application = app
logsRepo.TailLogMessages = logs
ui := callLogs(t, []string{"my-app"}, reqFactory, logsRepo)
assert.Equal(t, reqFactory.ApplicationName, "my-app")
assert.Equal(t, app, logsRepo.AppLogged)
assert.Equal(t, len(ui.Outputs), 2)
assert.Contains(t, ui.Outputs[0], "Connected, tailing logs for app")
assert.Contains(t, ui.Outputs[0], "my-app")
assert.Contains(t, ui.Outputs[0], "my-org")
assert.Contains(t, ui.Outputs[0], "my-space")
assert.Contains(t, ui.Outputs[0], "my-user")
assert.Contains(t, ui.Outputs[1], "Log Line 1")
}
开发者ID:jalateras,项目名称:cli,代码行数:34,代码来源:logs_test.go
示例16: CopyIn
func (c *Connection) CopyIn(handle, src, dst string) (*warden.CopyInResponse, error) {
res, err := c.RoundTrip(
&warden.CopyInRequest{
Handle: proto.String(handle),
SrcPath: proto.String(src),
DstPath: proto.String(dst),
},
&warden.CopyInResponse{},
)
if err != nil {
return nil, err
}
return res.(*warden.CopyInResponse), nil
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:16,代码来源:connection.go
示例17: TestStringEscaping
func TestStringEscaping(t *testing.T) {
testCases := []struct {
in *pb.Strings
out string
}{
{
// Test data from C++ test (TextFormatTest.StringEscape).
// Single divergence: we don't escape apostrophes.
&pb.Strings{StringField: proto.String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces")},
"string_field: \"\\\"A string with ' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"\n",
},
{
// Test data from the same C++ test.
&pb.Strings{StringField: proto.String("\350\260\267\346\255\214")},
"string_field: \"\\350\\260\\267\\346\\255\\214\"\n",
},
{
// Some UTF-8.
&pb.Strings{StringField: proto.String("\x00\x01\xff\x81")},
`string_field: "\000\001\377\201"` + "\n",
},
}
for i, tc := range testCases {
var buf bytes.Buffer
if err := proto.MarshalText(&buf, tc.in); err != nil {
t.Errorf("proto.MarsalText: %v", err)
continue
}
s := buf.String()
if s != tc.out {
t.Errorf("#%d: Got:\n%s\nExpected:\n%s\n", i, s, tc.out)
continue
}
// Check round-trip.
pb := new(pb.Strings)
if err := proto.UnmarshalText(s, pb); err != nil {
t.Errorf("#%d: UnmarshalText: %v", i, err)
continue
}
if !proto.Equal(pb, tc.in) {
t.Errorf("#%d: Round-trip failed:\nstart: %v\n end: %v", i, tc.in, pb)
}
}
}
开发者ID:hail100,项目名称:cli,代码行数:46,代码来源:text_test.go
示例18: init
func init() {
ext := &pb.Ext{
Data: proto.String("extension"),
}
if err := proto.SetExtension(cloneTestMessage, pb.E_Ext_More, ext); err != nil {
panic("SetExtension: " + err.Error())
}
}
开发者ID:hail100,项目名称:cli,代码行数:8,代码来源:clone_test.go
示例19: TestThatSignatureDoesNotValidateWhenItDoesntMatch
func TestThatSignatureDoesNotValidateWhenItDoesntMatch(t *testing.T) {
envelope := &LogEnvelope{
LogMessage: &LogMessage{},
RoutingKey: proto.String("app_id"),
Signature: []byte{0, 1, 2}, //some bad signature
}
assert.False(t, envelope.VerifySignature("super-secret"))
}
开发者ID:GABONIA,项目名称:cli,代码行数:9,代码来源:message_test.go
示例20: MarshalledLogEnvelope
func MarshalledLogEnvelope(unmarshalledMessage *logmessage.LogMessage, secret string) []byte {
envelope := &logmessage.LogEnvelope{
LogMessage: unmarshalledMessage,
RoutingKey: proto.String(*unmarshalledMessage.AppId),
}
envelope.SignEnvelope(secret)
return marshalProtoBuf(envelope)
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:9,代码来源:unmarshaller_suite_test.go
注:本文中的code/google/com/p/gogoprotobuf/proto.String函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论