ddns/hosts/hosts.go
Philipp Böhm 6af394aa2f refactor ddns into several packages and add tests for most important
components

WIP

restructure code into separate packages + add tests for request handling

more documentation for methods

remove useless comment
2017-07-02 20:46:28 +02:00

36 lines
569 B
Go

package hosts
import (
"crypto/sha1"
"fmt"
"strings"
"time"
)
type Host struct {
Hostname string `redis:"-"`
Ip string `redis:"ip"`
Token string `redis:"token"`
}
func (h *Host) GenerateAndSetToken() {
hash := sha1.New()
hash.Write([]byte(fmt.Sprintf("%d", time.Now().UnixNano())))
hash.Write([]byte(h.Hostname))
h.Token = fmt.Sprintf("%x", hash.Sum(nil))
}
func (h *Host) IsIPv4() bool {
if strings.Contains(h.Ip, ".") {
return true
}
return false
}
type HostBackend interface {
GetHost(string) (*Host, error)
SetHost(*Host) error
}