First working backend implementation

This commit is contained in:
Philipp Böhm 2014-07-12 23:37:01 +02:00
parent c44a18acb3
commit c6bf995d81
2 changed files with 49 additions and 11 deletions

View File

@ -5,8 +5,8 @@ import (
"fmt"
"github.com/garyburd/redigo/redis"
"log"
"time"
"strings"
"time"
)
const HostExpirationSeconds int = 10 * 24 * 60 * 60 // 10 Days
@ -78,5 +78,5 @@ func (self *Host) IsIPv4() bool {
return true
}
return False
return false
}

40
ddns.go
View File

@ -1,12 +1,14 @@
package main
import (
"bufio"
"fmt"
"github.com/gin-gonic/gin"
"github.com/pboehm/ddns/connection"
"log"
"net"
"os"
"strings"
)
func HandleErr(err error) {
@ -16,7 +18,43 @@ func HandleErr(err error) {
}
func RunBackend() {
/* code */
conn := connection.OpenConnection()
defer conn.Close()
fmt.Printf("OK\tDDNS Go Backend\n")
bio := bufio.NewReader(os.Stdin)
for {
line, _, err := bio.ReadLine()
HandleErr(err)
parts := strings.Split(string(line), "\t")
if len(parts) == 6 {
query_name := parts[1]
fqdn_parts := strings.Split(query_name, ".")
query_class := parts[2]
query_id := parts[4]
if len(fqdn_parts) > 0 {
if conn.HostExist(fqdn_parts[0]) {
host := conn.GetHost(fqdn_parts[0])
record := "A"
if !host.IsIPv4() {
record = "AAAA"
}
fmt.Printf("DATA\t%s\t%s\t%s\t10\t%s\t%s\n",
query_name, query_class, record, query_id, host.Ip)
}
}
}
fmt.Printf("END\n")
}
}
func RunWebService() {