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


Golang proto.String函数代码示例

本文整理汇总了Golang中code/google/com/p/gogoprotobuf/proto.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了String函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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