Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions tools/configtxlator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func main() {
// "version" command
case versionCmd.FullCommand():
fmt.Println(getVersionInfo())
default:
app.Fatalf("Unknown command")
}
}

Expand All @@ -121,7 +123,8 @@ func startServer(address string, cors []string) {
methods := handlers.AllowedMethods([]string{http.MethodPost})
headers := handlers.AllowedHeaders([]string{"Content-Type"})
logger.Infof("Serving HTTP requests on %s with CORS %v", listener.Addr(), cors)
err = http.Serve(listener, handlers.CORS(origins, methods, headers)(rest.NewRouter()))
corsHandler := handlers.CORS(origins, methods, headers)
err = http.Serve(listener, corsHandler(rest.NewRouter()))
} else {
logger.Infof("Serving HTTP requests on %s", listener.Addr())
err = http.Serve(listener, rest.NewRouter())
Expand All @@ -141,7 +144,11 @@ func encodeProto(msgName string, input, output *os.File) error {
if msgType == nil {
return errors.Errorf("message of type %s unknown", msgType)
}
msg := reflect.New(msgType.Elem()).Interface().(proto.Message)
msg, ok := reflect.New(msgType.Elem()).Interface().(proto.Message)

if !ok {
return errors.New("error marshaling: invalid type")
}

err = protolator.DeepUnmarshalJSON(input, msg)
if err != nil {
Expand Down Expand Up @@ -175,7 +182,10 @@ func decodeProto(msgName string, input, output *os.File) error {
if msgType == nil {
return errors.Errorf("message of type %s unknown", msgType)
}
msg := reflect.New(msgType.Elem()).Interface().(proto.Message)
msg, ok := reflect.New(msgType.Elem()).Interface().(proto.Message)
if !ok {
return errors.New("error marshaling: invalid type")
}

in, err := io.ReadAll(input)
if err != nil {
Expand Down Expand Up @@ -223,11 +233,12 @@ func computeUpdt(original, updated, output *os.File, channelID string) error {
return errors.Wrapf(err, "error computing config update")
}

cu.ChannelId = channelID

if cu == nil {
return errors.New("error marshaling computed config update: proto: Marshal called with nil")
}

cu.ChannelId = channelID

outBytes, err := proto.Marshal(cu)
if err != nil {
return errors.Wrapf(err, "error marshaling computed config update")
Expand Down