1
0
mirror of https://github.com/taigrr/godns synced 2025-01-18 04:03:25 -08:00

implement get domain id func

This commit is contained in:
Timothy 2014-05-13 13:08:43 +08:00
parent 43383a14f6
commit 18cae7e7f3
2 changed files with 30 additions and 36 deletions

View File

@ -1,9 +1,9 @@
package main package main
import ( import (
"fmt"
// "github.com/bitly/go-simplejson"
"encoding/json" "encoding/json"
"fmt"
"github.com/bitly/go-simplejson"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
@ -45,9 +45,9 @@ func api_version() {
post_data("/Info.Version", nil) post_data("/Info.Version", nil)
} }
func get_domain(name string) int { func get_domain(name string) int64 {
ret := -1 var ret int64
values := url.Values{} values := url.Values{}
values.Add("type", "all") values.Add("type", "all")
values.Add("offset", "0") values.Add("offset", "0")
@ -57,39 +57,33 @@ func get_domain(name string) int {
if err != nil { if err != nil {
fmt.Println("Failed to get domain list...") fmt.Println("Failed to get domain list...")
return ret return -1
} }
var list domain_list sjson, parse_err := simplejson.NewJson([]byte(response))
json.Unmarshal([]byte(response), &list)
// json, parse_err := simplejson.NewJson([]byte(response)) if parse_err != nil {
fmt.Println(parse_err.Error())
return -1
}
// if parse_err != nil { if sjson.Get("status").Get("code").MustString() == "1" {
// fmt.Println(parse_err.Error()) domains, _ := sjson.Get("domains").Array()
// }
// if json.Get("status").Get("code").MustString() == "1" { fmt.Println(domains)
// domains, _ := json.Get("domains").Array()
// // fmt.Println(string(domains)) for _, d := range domains {
// for _, d := range domains { m := d.(map[string]interface{})
// m := d.(map[string]interface{}) if m["name"] == name {
// if m["name"] == name { id := m["id"]
// id := simplejson.NewJson(m["id"]).Int()
// fmt.Println(id) switch t := id.(type) {
// } case json.Number:
// // if d["name"] == name { ret, _ = t.Int64()
// // fmt.Println(d["name"]) }
// // ret = d["id"] }
// // } }
// // if d == "name" { }
// // if v == name {
// // fmt.Println(v)
// // }
// // }
// }
// }
fmt.Printf("Domain id is: %d", ret) fmt.Printf("Domain id is: %d", ret)
return ret return ret

View File

@ -30,13 +30,13 @@ func dns_loop(loop chan bool) {
fmt.Println("Inside the loop...") fmt.Println("Inside the loop...")
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
currentIP, _ := get_currentIP(Configuration.IP_Url) // currentIP, _ := get_currentIP(Configuration.IP_Url)
fmt.Println("Current IP is" + currentIP) // fmt.Println("Current IP is" + currentIP)
//Continue to check the IP of sub-domain //Continue to check the IP of sub-domain
if len(currentIP) > 0 { // if len(currentIP) > 0 {
get_domain(Configuration.Domain) get_domain(Configuration.Domain)
} // }
api_version() api_version()
loop <- false loop <- false