How to re-implement parts of package os?

I’m new to Go, using it because there is an existing tool (a CLI called git-bug) which I wish to make use of in a web application running in the browser by compiling to WebAssembly. I’ve done some basic tests and have a ‘hello wasm’ app written in go.

My cunning plan requires that I fool the tool (git-bug) into working even though it expects a filesystem using the Go os package. So I’m looking for the best way to achieve this, such as:

  1. make it possible to call git-bug as a Golang library, by making a modified build of git-bug. I haven’t looked into that yet, because the second thing is more tricky, so I want to be sure i can do that first, which is…

  2. route any git-bug calls to the filesystem (via the os package) to my own library, which will provide a replica filesystem API, but in the browser.

So I’m looking for help on the second point first (although tips or pointers to examples on the first are welcome).

I have the Golang source and with it can see the code for the os package but am not sure of my options for substituting the relevant parts of the os package. For example, do I need to make a complete replica, or can I replace APIs at runtime?

And if I make a replica package, how would I cause git-bug to be built with that while minimising changes to the git-bug code (e.g. can I replace the os package with a custom build configuration?).

Thanks. For anyone interested, my project repo is safenetwork-gitportal.

I have a diagram which might help:

FYI:

io/fs: add file system interfaces #41190

File System Interfaces for Go — Draft Design

Thanks, I found those after I posted.

One thing which the reddit discussion lead me to was go-billy (which is by the author of go-git, a package used by git-bug), which looks as if it might help, but I haven’t looked into this yet.

I appreciate the references though, thanks.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.