github.com/MetalBlockchain/metalgo@v1.11.9/vms/rpcchainvm/ghttp/gwriter/writer_server.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package gwriter 5 6 import ( 7 "context" 8 "io" 9 10 writerpb "github.com/MetalBlockchain/metalgo/proto/pb/io/writer" 11 ) 12 13 var _ writerpb.WriterServer = (*Server)(nil) 14 15 // Server is an http.Handler that is managed over RPC. 16 type Server struct { 17 writerpb.UnsafeWriterServer 18 writer io.Writer 19 } 20 21 // NewServer returns an http.Handler instance managed remotely 22 func NewServer(writer io.Writer) *Server { 23 return &Server{writer: writer} 24 } 25 26 func (s *Server) Write(_ context.Context, req *writerpb.WriteRequest) (*writerpb.WriteResponse, error) { 27 n, err := s.writer.Write(req.Payload) 28 resp := &writerpb.WriteResponse{ 29 Written: int32(n), 30 } 31 if err != nil { 32 errStr := err.Error() 33 resp.Error = &errStr 34 } 35 return resp, nil 36 }