is there a way to mirror a standard package while adding some functions to it?

110 views
Skip to first unread message

Marwan abdel moneim

unread,
Jan 27, 2017, 10:19:17 PM1/27/17
to golang-nuts
i want to add few changes for the net/http package, while keeping the rest of the package as it is, but without copying the package source and put it in another one, i want my package to mirror whatever the package version installed

Matt Silverlock

unread,
Jan 28, 2017, 3:06:31 AM1/28/17
to golang-nuts
No, but without more context, do your changes require you to modify the package? Why not use wrap it?

Marwan abdel moneim

unread,
Jan 28, 2017, 3:12:44 AM1/28/17
to golang-nuts
do your changes require you to modify the package?
yes, i want to add some functions, but still provide all the package to the user 

Why not use wrap it?
i would have to wrap all the functions, very tedious 

Matt S

unread,
Jan 28, 2017, 3:26:59 AM1/28/17
to Marwan abdel moneim, golang-nuts
Which functions? What are you actually changing?

A wrapper library doesn't have to wrap all the functions: just wrap the ones you need to and make it a small, composable library. 



--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/g9NYQNaBBMA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marwan abdel moneim

unread,
Jan 28, 2017, 3:41:50 AM1/28/17
to golang-nuts, mrwn...@gmail.com
i want to do something like this

http.Handler{
  Action:   "Create new user",
  Method: "POST",
  URI:       "/users",
  Auth:      false,
  Params: []string{"name:max=100"},
  Do: func(r *http.Request) http.Response{
        ......
        return http.JSON(&user)
  }}

and do the common tasks like validation and authentication on a top layer
and could also generate a nice looking html file for the API 

Matt S

unread,
Jan 28, 2017, 3:49:43 AM1/28/17
to Marwan abdel moneim, golang-nuts
This definitely doesn't require you to modify net/http directly.

Just create a library with custom handler types that satisfy the http.Handler interface. Many existing Go routing libraries & frameworks will get you 90% of the way there.
--

Matt S

unread,
Jan 28, 2017, 3:50:08 AM1/28/17
to Marwan abdel moneim, golang-nuts
This definitely doesn't require you to modify net/http directly. 

Just create a library with custom handler types that satisfy the http.Handler interface. Many existing Go routing libraries & frameworks will get you 90% of the way there.

--

Marwan abdel moneim

unread,
Jan 28, 2017, 3:58:57 AM1/28/17
to golang-nuts, mrwn...@gmail.com
yes, you are right, if i am going to drop http.JSON and http.Response
i am trying to do that, i think it is better to make it small like you have said

thanks
Reply all
Reply to author
Forward
0 new messages