https://github.com/dector/nettw
Small network-related utilities for Go
https://github.com/dector/nettw
Last synced: 7 months ago
JSON representation
Small network-related utilities for Go
- Host: GitHub
- URL: https://github.com/dector/nettw
- Owner: dector
- Created: 2025-07-14T13:08:16.000Z (8 months ago)
- Default Branch: trunk
- Last Pushed: 2025-07-14T14:09:37.000Z (8 months ago)
- Last Synced: 2025-08-14T21:58:17.630Z (7 months ago)
- Language: Go
- Size: 1.95 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nettw
Small network-oriented Go library.
## Installation
```bash
go get github.com/dector/nettw
```
## Usage
### Get available port (preferebly user-specified)
Use `ParsePortOrPickAnother()`:
```go
package main
import (
"fmt"
"github.com/dector/nettw"
)
func main() {
port, err := nettw.ParsePortOrPickAnother("8080")
if err != nil {
panic(err)
}
// If port 8080 free - we will get it here.
// If not - random free port will be returned.
fmt.Printf("Using port: %d\n", port.Int)
}
```
### Getting a Port with Custom Arguments
Use `ParsePortOrPickAnotherWithArgs()`:
```go
package main
import (
"fmt"
"github.com/dector/nettw"
)
func main() {
port, err := nettw.ParsePortOrPickAnotherWithArgs(
"8080",
nettw.ParsePortArgs{
NewPortFrom: 3000,
NewPortTo: 4000,
MaxTries: 50,
}
)
if err != nil {
panic(err)
}
fmt.Printf("Using port: %d\n", port.Int)
}
```
## License
This project is licensed under the MIT License.