2018-08-01 15:15:38 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/gob"
|
2018-08-23 08:05:56 +01:00
|
|
|
"net/url"
|
|
|
|
"strings"
|
2018-08-01 15:15:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
2018-08-23 08:05:56 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|