use latest version of protoreflect (#212)

This commit is contained in:
Joshua Humphries
2021-02-22 17:32:40 -05:00
committed by GitHub
parent 1f34448998
commit 8d7770a962
28 changed files with 3169 additions and 2245 deletions

View File

@@ -1,9 +1,9 @@
package main
import (
"context"
"strings"
"golang.org/x/net/context"
"google.golang.org/grpc/metadata"
)

View File

@@ -1,12 +1,12 @@
package main
import (
"context"
"fmt"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/empty"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
syntax = "proto3";
option go_package = "main";
option go_package = ".;main";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

View File

@@ -1,14 +1,14 @@
package main
import (
"context"
"fmt"
"io"
"sync"
"github.com/golang/protobuf/ptypes"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
)
// chatServer implements the Support gRPC service, for providing
@@ -134,7 +134,7 @@ func (s *chatServer) ChatCustomer(stream Support_ChatCustomerServer) error {
}
entry := &ChatEntry{
Date: ptypes.TimestampNow(),
Date: timestamppb.Now(),
Entry: &ChatEntry_CustomerMsg{
CustomerMsg: req.Msg,
},
@@ -279,7 +279,7 @@ func (s *chatServer) ChatAgent(stream Support_ChatAgentServer) error {
}
entry := &ChatEntry{
Date: ptypes.TimestampNow(),
Date: timestamppb.Now(),
Entry: &ChatEntry_AgentMsg{
AgentMsg: &AgentMessage{
AgentName: agent,

View File

@@ -1,14 +1,13 @@
package main
import (
"bytes"
"fmt"
"sync"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/ptypes"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/timestamppb"
)
// In-memory database that is periodically saved to a JSON file.
@@ -43,7 +42,7 @@ func (a *accounts) openAccount(customer string, accountType Account_Type, initia
acct.Transactions = append(acct.Transactions, &Transaction{
AccountNumber: num,
SeqNumber: 1,
Date: ptypes.TimestampNow(),
Date: timestamppb.Now(),
AmountCents: initialBalanceCents,
Desc: "initial deposit",
})
@@ -130,7 +129,7 @@ func (a *account) newTransaction(amountCents int32, desc string) (newBalance int
a.BalanceCents = bal
a.Transactions = append(a.Transactions, &Transaction{
AccountNumber: a.AccountNumber,
Date: ptypes.TimestampNow(),
Date: timestamppb.Now(),
AmountCents: amountCents,
SeqNumber: uint64(len(a.Transactions) + 1),
Desc: desc,
@@ -139,16 +138,11 @@ func (a *account) newTransaction(amountCents int32, desc string) (newBalance int
}
func (t *Transaction) MarshalJSON() ([]byte, error) {
var jsm jsonpb.Marshaler
var buf bytes.Buffer
if err := jsm.Marshal(&buf, t); err != nil {
return nil, err
}
return buf.Bytes(), nil
return protojson.Marshal(t)
}
func (t *Transaction) UnmarshalJSON(b []byte) error {
return jsonpb.Unmarshal(bytes.NewReader(b), t)
return protojson.Unmarshal(b, t)
}
func (a *accounts) clone() *accounts {

View File

@@ -3,6 +3,7 @@ package main
//go:generate protoc --go_out=plugins=grpc:./ bank.proto support.proto
import (
"context"
"encoding/json"
"flag"
"fmt"
@@ -14,7 +15,6 @@ import (
"syscall"
"time"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/peer"

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
syntax = "proto3";
option go_package = "main";
option go_package = ".;main";
import "google/protobuf/timestamp.proto";

View File

@@ -2,6 +2,7 @@
package main
import (
"context"
"flag"
"fmt"
"net"
@@ -9,7 +10,6 @@ import (
"sync/atomic"
"time"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"