mirror of
https://github.com/taigrr/godns
synced 2025-01-18 04:03:25 -08:00
add parse json logic
This commit is contained in:
parent
7c4f680dc9
commit
43383a14f6
@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
// "github.com/bitly/go-simplejson"
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -43,6 +45,56 @@ func api_version() {
|
|||||||
post_data("/Info.Version", nil)
|
post_data("/Info.Version", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func get_domain(name string) int {
|
||||||
|
|
||||||
|
ret := -1
|
||||||
|
values := url.Values{}
|
||||||
|
values.Add("type", "all")
|
||||||
|
values.Add("offset", "0")
|
||||||
|
values.Add("length", "20")
|
||||||
|
|
||||||
|
response, err := post_data("/Domain.List", values)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to get domain list...")
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
var list domain_list
|
||||||
|
json.Unmarshal([]byte(response), &list)
|
||||||
|
|
||||||
|
// json, parse_err := simplejson.NewJson([]byte(response))
|
||||||
|
|
||||||
|
// if parse_err != nil {
|
||||||
|
// fmt.Println(parse_err.Error())
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if json.Get("status").Get("code").MustString() == "1" {
|
||||||
|
// domains, _ := json.Get("domains").Array()
|
||||||
|
|
||||||
|
// // fmt.Println(string(domains))
|
||||||
|
// for _, d := range domains {
|
||||||
|
// m := d.(map[string]interface{})
|
||||||
|
// if m["name"] == name {
|
||||||
|
// id := simplejson.NewJson(m["id"]).Int()
|
||||||
|
// fmt.Println(id)
|
||||||
|
// }
|
||||||
|
// // if d["name"] == name {
|
||||||
|
// // fmt.Println(d["name"])
|
||||||
|
// // ret = d["id"]
|
||||||
|
// // }
|
||||||
|
// // if d == "name" {
|
||||||
|
// // if v == name {
|
||||||
|
// // fmt.Println(v)
|
||||||
|
// // }
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
fmt.Printf("Domain id is: %d", ret)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func post_data(url string, content url.Values) (string, error) {
|
func post_data(url string, content url.Values) (string, error) {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
values := generate_header(content)
|
values := generate_header(content)
|
||||||
|
2
godns.go
2
godns.go
@ -35,7 +35,7 @@ func dns_loop(loop chan bool) {
|
|||||||
|
|
||||||
//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)
|
||||||
}
|
}
|
||||||
|
|
||||||
api_version()
|
api_version()
|
||||||
|
20
response_entity.go
Normal file
20
response_entity.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type status struct {
|
||||||
|
code string
|
||||||
|
message string
|
||||||
|
created_at string
|
||||||
|
}
|
||||||
|
|
||||||
|
type domain struct {
|
||||||
|
id int
|
||||||
|
name string
|
||||||
|
status string
|
||||||
|
records string
|
||||||
|
owner string
|
||||||
|
}
|
||||||
|
|
||||||
|
type domain_list struct {
|
||||||
|
ret_status status
|
||||||
|
domains []domain
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user