Use the io.Reader interface

This commit is contained in:
Kovid Goyal
2022-08-18 10:36:04 +05:30
parent a7bc2fcba8
commit 6c3a439455
3 changed files with 25 additions and 3 deletions

19
tools/utils/io.go Normal file
View File

@@ -0,0 +1,19 @@
package utils
import (
"io"
)
type BytesReader struct {
Data []byte
Pos int64
}
func (self *BytesReader) Read(b []byte) (n int, err error) {
if self.Pos >= int64(len(self.Data)) {
return 0, io.EOF
}
n = copy(b, self.Data[self.Pos:])
self.Pos += int64(n)
return
}

View File

@@ -2,9 +2,10 @@ package utils
import (
"fmt"
"github.com/seancfoley/ipaddress-go/ipaddr"
"runtime"
"strings"
"github.com/seancfoley/ipaddress-go/ipaddr"
)
func Cut(s string, sep string) (string, string, bool) {
@@ -21,7 +22,7 @@ func ParseSocketAddress(spec string) (network string, addr string, err error) {
return
}
if network == "unix" {
if strings.HasSuffix(addr, "@") && runtime.GOOS != "linux" {
if strings.HasPrefix(addr, "@") && runtime.GOOS != "linux" {
err = fmt.Errorf("Abstract UNIX sockets are only supported on Linux. Cannot use: %s", spec)
}
return