Unknown field 'content' in struct literal of type tycoon_services.Msg

19 views
Skip to first unread message

Jesse Thompson

unread,
May 3, 2022, 11:09:36 AMMay 3
to Protocol Buffers
sms_server.go

```
package main

import (
    "context"
    "log"
    "math/rand"
    "net"

    pb "tycoon.systems/tycoon-services/sms"
)

const (
    port = ":6000"
)

type SmsManagementServer struct {
    pb.UnimplementedSmsManagementServer
}

func (s *SmsManagementServer) CreateNewSmsBlast(ctx context.Context, in *pb.NewMsg) (*pb.Msg, error) {
    log.PrintF("Received: %v, %v", in.GetContent(), in.GetFrom())
    jobId := uuid.New()
    return &pb.Msg{content: in.GetContent(), from: in.getFrom(), jobId: jobId }, nil
}

func main() {
    lis, err := net.Listen("tcp", port)
    if err != nil {
        log.Fatalf("Failed to listen: %v", err)
    }

    s := grpc.NewServer()
    pb.RegisterSmsManagementServer(s, &SmsManagementServer{})
    log.Printf("Server listening at %v", lis.Addr())
    if err := s.Serve(lis); err != nil {
        log.Fatalf("Failed to server: %v", err)
    }
}
```

On line ```log.PrintF("Received: %v, %v", in.GetContent(), in.GetFrom())``` I am getting "undefined: log.PrintF go"

and on line ```return &pb.Msg{content: in.GetContent(), from: in.getFrom(), jobId: jobId }, nil``` I am getting "unknown field 'from' in struct literal of type tycoon_services.Msg go
"

My sms.proto is defined here 
```
syntax = "proto3";

package sms;

option go_package = "tycoon.systems/tycoon-services;tycoon_services";

service smsManagement {
    rpc CreateNewSmsBlast (NewMsg) returns (Msg) {}
}

message NewMsg {
    string from = 1;
    string content = 2;
}

message Msg {
    string from = 1;
    string content = 2;
    int32 jobId = 3;
}
```

The command I've ran to build the proto files is
```
$ protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./sms/sms.proto
```

I am unsure where Im going wrong. Im more familiar with Node.js as opposed to go. Why are my log methods undefined?

Jesse Thompson

unread,
May 3, 2022, 11:19:28 AMMay 3
to Protocol Buffers
Yikes, I feel pretty dumb. The tutorial I was watching had log.PrintF typed (I know the capital F looked really weird).

Although in regards to the unknown fields on my created sms blast I am a little confused.

I am sending an sms blast with content string and a from (User phone number) from Next.js to my node.js server via socket.io (none of this matters, but im saying it anyways). My goal is to send this object to my go server so that go can process a twilio job with https://github.com/hibiken/asynq

Jesse Thompson

unread,
May 3, 2022, 11:22:38 AMMay 3
to Protocol Buffers
Reply all
Reply to author
Forward
0 new messages