Remove ConnectToTcp util
This commit is contained in:
parent
02e1483b98
commit
7969fbcbea
18
utils.go
18
utils.go
|
@ -5,14 +5,10 @@ import (
|
|||
"io"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Port io.ReadWriteCloser
|
||||
|
||||
func Every(t string, f func()) {
|
||||
dur := parseDuration(t)
|
||||
go func() {
|
||||
|
@ -51,14 +47,6 @@ func Rand(max int) int {
|
|||
return rand.Intn(max)
|
||||
}
|
||||
|
||||
func ConnectToTcp(port string) io.ReadWriteCloser {
|
||||
tcpPort, err := net.Dial("tcp", port)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return tcpPort
|
||||
}
|
||||
|
||||
func ConnectToSerial(port string, baud int) io.ReadWriteCloser {
|
||||
c := &serial.Config{Name: port, Baud: baud}
|
||||
s, err := serial.OpenPort(c)
|
||||
|
@ -68,12 +56,6 @@ func ConnectToSerial(port string, baud int) io.ReadWriteCloser {
|
|||
return s
|
||||
}
|
||||
|
||||
func IsUrl(s string) bool {
|
||||
ip := regexp.MustCompile("([^A-Za-z0-9]+).([^A-Za-z0-9]+).([^A-Za-z0-9]+)")
|
||||
url := regexp.MustCompile("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?")
|
||||
return ip.MatchString(s) || url.MatchString(s)
|
||||
}
|
||||
|
||||
func Call(thing interface{}, method string, params ...interface{}) []reflect.Value {
|
||||
in := make([]reflect.Value, len(params))
|
||||
for k, param := range params {
|
||||
|
|
|
@ -57,11 +57,6 @@ var _ = Describe("Utils", func() {
|
|||
Expect(ToScale(-1, 0, 10)).To(Equal(float64(0)))
|
||||
Expect(ToScale(0.5, 0, 10)).To(Equal(float64(5)))
|
||||
})
|
||||
It("should return true on url or ip address", func() {
|
||||
Expect(IsUrl("127.0.0.1")).To(Equal(true))
|
||||
Expect(IsUrl("http://www.google.com")).To(Equal(true))
|
||||
Expect(IsUrl("/dev/ttyACM0")).To(Equal(false))
|
||||
})
|
||||
It("should return random int", func() {
|
||||
a := Rand(100)
|
||||
b := Rand(100)
|
||||
|
|
Loading…
Reference in New Issue