go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

Added Server.Unwrap function

Open handicraftsman opened this issue 3 years ago • 5 comments

This is a tiny commit, mostly for internal use.

I did it to support adding middlewares (such as logging, which is my case) over the http.ServeMux generated by the Dapr SDK.

It is probably not the cleanest way to do that though, as you still need to cast the daprd.NewServiceWithMux() output with s.(*daprd.Server)

handicraftsman avatar Apr 27 '21 18:04 handicraftsman

@skyao please review this

yaron2 avatar May 04 '21 16:05 yaron2

// Gets the underlying serve address and http.ServeMux
func (s *Server) Unwrap() (string, *http.ServeMux) {
	return s.address, s.mux
}

This function exposures the underlying implementation details, it is realy NOT a clean way as you say. It breaks the design, can we find a better way?

skyao avatar May 07 '21 09:05 skyao

I don't know, for this specific case it would be a good idea to implement adding middlewares on top of the internal handler, while not exposing the values like i did in my commit.

Or it should be possible to start treating the returned values as public, while also making sure that you cannot use the Server structure anymore (because messing with these values WILL break it).

handicraftsman avatar May 07 '21 11:05 handicraftsman

@skyao what do you think?

yaron2 avatar May 24 '21 16:05 yaron2

@skyao what do you think?

I have given my comments: I understand the requirement from , but I think we need find a better way, which won't break the design.

skyao avatar May 25 '21 07:05 skyao