storj/pkg/utils/utils.go
Egon Elbre f80185a807
Preliminary support for windows (#266)
* Don't use url.Parse for bolt paths: filepaths may not be valid URL-s.
* go.mod: update dependencies
* README.md: add Windows instructions
* pkg/overlay: check for the correct path and text in error
* pkg/overlay: fix tests for windows
* pkg/piecestore: make windows tests pass
* pkg/telemetry: skip test, as it doesn't shutdown nicely
* storage/redis: ensure that redis is clean before running tests
2018-08-23 10:05:56 +03:00

34 lines
610 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package utils
import (
"bytes"
"encoding/gob"
"net/url"
"strings"
)
// GetBytes transforms an empty interface type into a byte slice
func GetBytes(key interface{}) ([]byte, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
err := enc.Encode(key)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func ParseURL(s string) (*url.URL, error) {
if strings.HasPrefix(s, "bolt://") {
return &url.URL{
Scheme: "bolt",
Path: strings.TrimPrefix(s, "bolt://"),
}, nil
}
return url.Parse(s)
}