dispatchrun / net

Go package implementing WASI socket extensions
Apache License 2.0
141 stars 8 forks source link

more integrations with client network packages #5

Closed achille-roussel closed 1 year ago

achille-roussel commented 1 year ago

This PR changes the project layout to have one directory per protocol:

.
├── http
│   ├── http.go
│   ├── http_wasip1.go
│   └── http_wasip1_test.go
├── mysql
│   ├── go.mod
│   ├── go.sum
│   ├── mysql.go
│   ├── mysql_wasip1.go
│   └── mysql_wasip1_test.go
├── wasip1
│   ├── dial_wasip1.go
│   ├── listen_wasip1.go
│   ├── lookup_wasip1.go
│   ├── lookup_wasip1_purego.go
│   ├── net_wasip1.go
│   ├── net_wasip1_test.go
│   └── syscall_wasmedge_wasip1.go

The intent is to allow finer grain configuration of the imports and mutations of the program default state.

For the mysql client, we can register a global dialer function that the driver uses, which makes it possible for us to provide a one line import experience to configure a program which connects to MySQL. I placed this under a separate submodule to avoid forcing a dependency on the mysql driver in applications that don't need it.

I also added a wasip1.Dialer type modeled after net.Dialer which allows configuring the dialer function on github.com/lib/pq.

The README needs a refresher, and I would like to add more packages showing how to configure clients for more protocols, but I wanted to share progress first in case you all had any feedback on the approach.

achille-roussel commented 1 year ago

I wonder if we could submit PRs to the other major libraries to do the same? We could make it backwards compatible by letting you define a global dial function, but then allowing for overrides when you configure a single instance. Then we could have one line imports (with side effects) for all libraries.

It would be a great initiative to take; I expect there may be some reluctance from maintainers who have already provided a way to customize the dialer and may not want to commit to the extra code to maintain. Let's engage in those conversations after the OSS release when we can show people why it's a good model!