Example #1
0
func GetRecordList(domainId int) []g.RecordResult {
	data := url.Values{}

	data.Add("login_email", g.Config().LoginEmail)
	data.Add("login_password", g.Config().LoginPassword)
	data.Add("format", "json")
	data.Add("domain_id", strconv.Itoa(domainId))

	strResponse, err := Post("https://dnsapi.cn/Record.List", data)
	if nil == err && "" != strResponse && strings.Contains(strResponse, `"code":"1"`) {
		var rlr g.RecordListResult
		err = json.Unmarshal(bytes.NewBufferString(strResponse).Bytes(), &rlr)
		if nil != err {
			logger.Error("decode RECORD_LIST response fail %v\n", err)
		} else {
			var records []g.RecordResult
			for _, record := range rlr.Records {
				if "A" != record.Type {
					continue
				}
				records = append(records, record)
				logger.Info("domain_id:%d,name:%s,record_id:%s,name:%s,value:%s,status:%s\n",
					domainId, rlr.Domain.Name, record.Id, record.Name, record.Value, record.Status)
			}

			return records
		}
	} else {
		logger.Error("GET_RECORD_LIST RESPONSE<<<====%s, error: %v", strResponse, err)
	}
	return nil
}
Example #2
0
func GetDomainList() []g.DomainResult {
	data := url.Values{}

	data.Add("login_email", g.Config().LoginEmail)
	data.Add("login_password", g.Config().LoginPassword)
	data.Add("format", "json")

	strResponse, err := Post("https://dnsapi.cn/Domain.List", data)
	if nil == err && "" != strResponse && strings.Contains(strResponse, `"code":"1"`) {
		var dlr g.DomainListResult
		err = json.Unmarshal(bytes.NewBufferString(strResponse).Bytes(), &dlr)
		if nil != err {
			logger.Errorln("decode DOMAIN_LIST response fail %v\n", err)
		} else {
			for _, domain := range dlr.Domains {
				logger.Info("domain_id:%d,name:%s,created:%v,updated:%v\n", domain.Id, domain.Name, domain.Created, domain.Updated)
			}
			return dlr.Domains
		}
	} else {
		logger.Error("GET_DOMAIN_LIST RESPONSE<<<====%s, error: %v", strResponse, err)
	}
	return nil
}
Example #3
0
func initConnPools() error {
	cfg := g.Config()
	if cfg.LogLevel == "trace" || cfg.LogLevel == "debug" {
		conn_pool.EnableSlowLog(true, cfg.SlowLog)
	}

	var (
		tmp_addrs map[string][]string
		tmp_pools map[string]*conn_pool.ConnPool
	)

	backend.RLock()
	tmp_addrs = backend.Addrs
	tmp_pools = backend.Pools
	backend.RUnlock()

	c := cfg.Graph
	for name, addr_list := range tmp_addrs {
		for _, addr := range addr_list {
			if _, ok := tmp_pools[addr]; !ok {
				pool := conn_pool.NewConnPool(addr, c.MaxConns, c.MaxIdle)

				pool.New = func() (io.Closer, error) {
					_, err := net.ResolveTCPAddr("tcp", pool.Name)
					if err != nil {
						return nil, err
					}
					conn, err := net.DialTimeout("tcp", pool.Name, time.Duration(c.Timeout)*time.Millisecond)
					if err != nil {
						return nil, err
					}

					return RpcConn{rpc.NewClient(conn)}, nil
				}

				pool.Ping = func(conn io.Closer) error {
					rpc_conn := conn.(RpcConn)
					if rpc_conn.cli == nil {
						return errors.New("nil conn")
					}

					resp := &model.SimpleRpcResponse{}
					err := rpc_conn.cli.Call("Graph.Ping", model.NullRpcRequest{}, resp)
					logger.Trace("Graph.Ping resp: %v", resp)

					return err
				}

				tmp_pools[addr] = pool
				logger.Info("create the pool: %s %s", name, addr)
			} else {
				logger.Trace("keep the pool: %s %s", name, addr)
			}
		}
	}

	backend.Lock()
	defer backend.Unlock()
	backend.Pools = tmp_pools

	return nil
}