Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vansante/go-network-file
Provides an io.ReadSeeker and io.WriteSeeker interface over the network.
https://github.com/vansante/go-network-file
file-reader file-writer golang golang-library network-server
Last synced: about 1 month ago
JSON representation
Provides an io.ReadSeeker and io.WriteSeeker interface over the network.
- Host: GitHub
- URL: https://github.com/vansante/go-network-file
- Owner: vansante
- License: mit
- Created: 2019-10-05T09:31:29.000Z (about 5 years ago)
- Default Branch: v2
- Last Pushed: 2023-09-25T13:09:25.000Z (about 1 year ago)
- Last Synced: 2024-07-20T20:03:50.172Z (5 months ago)
- Topics: file-reader, file-writer, golang, golang-library, network-server
- Language: Go
- Homepage:
- Size: 127 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-network-file
Provides an io.ReaderAt and io.WriterAt interface over the network using simple HTTP calls.## Installation
```
go get gopkg.in/vansante/go-network-file.v2
```## Documentation
https://pkg.go.dev/gopkg.in/vansante/go-network-file.v2
## Basic usage
To start a file server, do:
```golang
srv := NewFileServer("/my-files", "mySecretCode")
err := http.ListenAndServe(":8080", srv)
if err != nil {
panic(err)
}
```Now we want to create a file that we can write to remotely:
```golang
file, err := os.CreateTemp(os.TempDir(), "New Test File.txt")
assert.NoError(t, err)
defer func() {
_ = file.Close()
}()ctx, cancelFn := context.WithTimeout(context.Background(), time.Minute)
defer cancelFn()err = srv.ServeFileWriter(ctx, fileID, dst)
if err != nil {
panic(err)
}
```Then on the client side, we open a writer for this file:
```golang
ctx, cancelFn := context.WithTimeout(context.Background(), time.Minute)
defer cancelFn()wrtr := NewWriter(ctx, "http://my-file-server:8080/my-files", "mySecretCode", fileID)
_, err := wrtr.Write([]byte("Hello, World!"))
if err != nil {
panic(err)
}
err = wrtr.Close()
if err != nil {
panic(err)
}
```