I'm using grpc in golang and want to make my header like this
I already tried 2 methode. First, i'm using this answer and it works, but the header is adding grpc-metadata- to it's key like this
My question is how to remove that word? and how to generate some values like date,content-length, cache-control etc, do i have to hardcoded it in my code like this?
header := metadata.New(map[string]string{"Access-Control-Allow-Headers": "X-Requested-With,content-type, Accept,Authorization", "Server": "val2"})
grpc.SendHeader(ctx, header)
And the other methode is i'm using http.Responsewritter. this is my code like:
main.go
var (
config *envcfg.Envcfg
logger *logrus.Logger
https http.ResponseWriter
)
func main() {
--------------------
g.Go(func() error { return NewGRPCServer(config, logger, https) })
-------------------
}
func NewGRPCServer(config *envcfg.Envcfg, logger *logrus.Logger, https http.ResponseWriter) error {
// create service handlers each grpc service server
signupSvc, err := signup.New(config, logger, https)
if err != nil {
return err
}
-----------------------------
// register grpc service server
grpcServer := grpc.NewServer()
supb.RegisterSignServer(grpcServer, signupSvc)
-------------------------------------------------------
}
api.go :
type Server struct {
config ConfigStore
logger Logger
https http.ResponseWriter
}
func New(config ConfigStore, logger Logger, https http.ResponseWriter) (*Server, error) {
return &Server{
config: config,
logger: logger,
https: https,
}, nil
}
function.go:
func (s *Server) SplashScreen(ctx context.Context,req *supb.RetrieveRequest, w http.ResponseWriter) (*supb.RetrieveResponse,error){
// do something
}
The problem is in main it said that signupSVC doesn't implement signServer like this:
Cannot use 'signupSvc' (type *Server) as type SignServer Type does not implement 'SignServer' need method: SplashScreen(context.Context, *RetrieveRequest) (*RetrieveResponse, error) have method: SplashScreen(ctx context.Context, req *supb.RetrieveRequest, w http.ResponseWriter) (*supb.RetrieveResponse, error)
where to place the http.Responsewriter ?