当前位置: 首页>>代码示例>>Golang>>正文


Golang MyError.NewError函数代码示例

本文整理汇总了Golang中MyError.NewError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewError函数的具体用法?Golang NewError怎么用?Golang NewError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ParseSOA

func ParseSOA(d string, r []dns.RR) (*dns.SOA, []*dns.NS, *MyError.MyError) {
	var soa *dns.SOA
	var ns_a []*dns.NS
	for _, v := range r {
		vh := v.Header()
		if vh.Name == dns.Fqdn(d) || dns.IsSubDomain(vh.Name, dns.Fqdn(d)) {
			switch vh.Rrtype {
			case dns.TypeSOA:
				if vv, ok := v.(*dns.SOA); ok {
					//fmt.Print(utils.GetDebugLine(), "ParseSOA:  ", vv)
					soa = vv
					utils.ServerLogger.Debug("ParseSOA: %v", vv)
				}
			case dns.TypeNS:
				if vv, ok := v.(*dns.NS); ok {
					ns_a = append(ns_a, vv)
				}
			default:
				//fmt.Println(utils.GetDebugLine(), " PasreSOA: error unexpect: ", v)
				utils.ServerLogger.Error("ParseSOA: error unexpect %v", v)
			}
		} else {
			//fmt.Print(utils.GetDebugLine(), "ParseSOA 258 ")
			//fmt.Println(utils.GetDebugLine(), vh.Name+" not match "+d)
			utils.ServerLogger.Debug("%s not match %s", vh.Name, d)
			return nil, nil, MyError.NewError(MyError.ERROR_NOTVALID, d+" has no SOA record,try parent")
		}

	}
	if soa != nil {
		return soa, ns_a, nil
	} else {
		return nil, nil, MyError.NewError(MyError.ERROR_NORESULT, "No SOA record for domain "+d)
	}
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:35,代码来源:query_dns.go

示例2: GetRegionWithIPFromMySQL

func (D *RR_MySQL) GetRegionWithIPFromMySQL(ip uint32) (*MySQLRegion, *MyError.MyError) {
	if e := D.DB.Ping(); e != nil {
		if ok := InitMySQL(RC_MySQLConf); ok != true {
			return nil, MyError.NewError(MyError.ERROR_UNKNOWN, "Connect MySQL Error")
		}
	}
	sqlstring := "Select idRegion, StartIP, EndIP, NetAddr, NetMask From " + RegionTable + " Where ? >= StartIP and ? <= EndIP"
	var idRegion, StartIP, EndIP, NetAddr, NetMask uint32
	ee := D.DB.QueryRow(sqlstring, ip, ip).Scan(&idRegion, &StartIP, &EndIP, &NetAddr, &NetMask)
	switch {
	case ee == sql.ErrNoRows:
		utils.QueryLogger.Error(ee.Error())
		return nil, MyError.NewError(MyError.ERROR_NOTFOUND, "Not found for Region for IP: "+strconv.Itoa(int(ip)))
	case ee != nil:
		utils.QueryLogger.Error(ee.Error())

		return nil, MyError.NewError(MyError.ERROR_UNKNOWN, ee.Error())
	default:
		utils.QueryLogger.Debug("GetRegionWithIPFromMySQL: ",
			" idRegion: ", idRegion, " StartIP: ", StartIP, " EndIP: ", EndIP, " NetAddr: ",
			NetAddr, " NetMask: ", NetMask, " srcIP: ", utils.Int32ToIP4(ip).String())
		return &MySQLRegion{
			IdRegion: idRegion,
			Region: &RegionNew{
				StarIP:  StartIP,
				EndIP:   EndIP,
				NetAddr: NetAddr,
				NetMask: NetMask},
		}, nil
	}
	return nil, MyError.NewError(MyError.ERROR_UNKNOWN, "Unknown error!")
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:32,代码来源:query_mysql.go

示例3: GenerateParentDomain

func GenerateParentDomain(d string) (string, *MyError.MyError) {
	x := dns.SplitDomainName(d)
	if cap(x) > 1 {
		//		fmt.Println(x)
		return strings.Join(x[1:], "."), nil
	} else {
		return d, MyError.NewError(MyError.ERROR_NORESULT, d+" has no subdomain")
	}
	return d, MyError.NewError(MyError.ERROR_UNKNOWN, d+" unknown error")
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:10,代码来源:query_dns.go

示例4: Int32ToIpNet

//Parse ip(uint32) and mask(int) to *net.IPNe
func Int32ToIpNet(ip uint32, mask int) (*net.IPNet, *MyError.MyError) {
	if mask < 0 || mask > 32 {
		return nil, MyError.NewError(MyError.ERROR_NOTVALID, "invalid mask error, param: "+strconv.Itoa(mask))
	}
	ipaddr := Int32ToIP4(ip)

	cidr := strings.Join([]string{ipaddr.String(), strconv.Itoa(mask)}, "/")
	_, ipnet, ok := net.ParseCIDR(cidr)
	if ok != nil {
		return nil, MyError.NewError(MyError.ERROR_NOTVALID, "ParseCIDR error, param: "+cidr)
	}
	return ipnet, nil
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:14,代码来源:utils.go

示例5: GetDomainSOANodeFromCache

func (ST *DomainSOATree) GetDomainSOANodeFromCache(dsn *DomainSOANode) (*DomainSOANode, *MyError.MyError) {
	ST.RWMutex.RLock()
	defer ST.RWMutex.RUnlock()
	if dt := ST.LLRB.Get(dsn); dt != nil {
		if dsn_r, ok := dt.(*DomainSOANode); ok {
			return dsn_r, nil
		} else {
			return nil, MyError.NewError(MyError.ERROR_TYPE, "ERROR_TYPE")
		}
	} else {
		return nil, MyError.NewError(MyError.ERROR_NOTFOUND, "Not found soa record from DomainSOACache via domainname "+dsn.SOAKey)
	}
	return nil, MyError.NewError(MyError.ERROR_UNKNOWN, "Unknown Error!")
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:14,代码来源:domain.go

示例6: GetDomainNodeFromCache

func (DT *DomainRRTree) GetDomainNodeFromCache(d *Domain) (*DomainNode, *MyError.MyError) {
	DT.RWMutex.RLock()
	defer DT.RWMutex.RUnlock()
	dr := DT.LLRB.Get(d)
	if dr != nil {
		if drr, ok := dr.(*DomainNode); ok {
			return drr, nil
		} else {
			return nil, MyError.NewError(MyError.ERROR_TYPE, "Got error result because of the type of return value is "+reflect.TypeOf(dr).String())
		}
	} else {
		return nil, MyError.NewError(MyError.ERROR_NOTFOUND, "Not found DomainNode from DomainRRCache for param: "+reflect.ValueOf(d.DomainName).String())
	}
	return nil, MyError.NewError(MyError.ERROR_UNKNOWN, "SearchDomainNode got param: "+reflect.ValueOf(d).String())
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:15,代码来源:domain.go

示例7: GetAFromCache

func GetAFromCache(dst, srcIP string) (*DomainNode, []dns.RR, *MyError.MyError) {
	dn, e := DomainRRCache.GetDomainNodeFromCacheWithName(dst)
	if e == nil && dn != nil && dn.DomainRegionTree != nil {
		//Get DomainNode succ,
		r, e := dn.DomainRegionTree.GetRegionFromCacheWithAddr(
			utils.Ip4ToInt32(net.ParseIP(srcIP)), DefaultRadixSearchMask)
		if e == nil && len(r.RR) > 0 {
			if r.RrType == dns.TypeA {
				utils.ServerLogger.Debug("GetAFromCache: Goooot A ", dst, srcIP, r.RR)
				return dn, r.RR, nil
			} else if r.RrType == dns.TypeCNAME {
				utils.ServerLogger.Debug("GetAFromCache: Goooot CNAME ", dst, srcIP, r.RR)
				return dn, r.RR, MyError.NewError(MyError.ERROR_CNAME,
					"Get CNAME From,Requery A for "+r.RR[0].(*dns.CNAME).Target)
			}
		}

		return dn, nil, MyError.NewError(MyError.ERROR_NOTFOUND,
			"Not found R in cache, dst :"+dst+" srcIP "+srcIP)
		// return
	} else if e == nil && dn != nil && dn.DomainRegionTree == nil {
		// Get domainNode in cache tree,but no RR in region tree,need query with NS
		// if RegionTree is nil, init RegionTree First
		ok, e := dn.InitRegionTree()
		if e != nil {
			utils.ServerLogger.Error("InitRegionTree fail %s", e.Error())
		}
		//
		//fmt.Println("RegionTree is nil ,Init it: "+reflect.ValueOf(ok).String(), e)
		utils.ServerLogger.Debug("RegionTree is nil ,Init it: %s ", reflect.ValueOf(ok).String())
		return dn, nil, MyError.NewError(MyError.ERROR_NORESULT,
			"Get domainNode in cache tree,but no RR in region tree,need query with NS, dst : "+dst+" srcIP "+srcIP)
	} else {
		// e != nil
		// RegionTree is not nil
		if e != nil {
			if e.ErrorNo != MyError.ERROR_NOTFOUND {
				//fmt.Println("Found unexpected error, need return !")
				utils.ServerLogger.Info("Not found, need return :", "error :", e, "dn:", dn)
				//os.Exit(2)
			} else {
				utils.ServerLogger.Critical("Found unexpected error, need return !", "error :", e, "dn:", dn)
			}
		}
		return nil, nil, e
	}
	return nil, nil, MyError.NewError(MyError.ERROR_UNKNOWN, "Unknown error!")
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:48,代码来源:wrapper.go

示例8: GetRegionFromCacheWithAddr

func (RT *RegionTree) GetRegionFromCacheWithAddr(addr uint32, mask int) (*Region, *MyError.MyError) {
	RT.RWMutex.RLock()
	defer RT.RWMutex.RUnlock()
	if r := RT.Radix32.Find(addr, mask); r != nil && r.Value != nil {
		//fmt.Println(utils.GetDebugLine(), "GetRegionFromCacheWithAddr : ", r, addr, reflect.TypeOf(addr), mask, reflect.TypeOf(mask))
		utils.ServerLogger.Debug("GetRegionFromCacheWithAddr: ", r, addr, reflect.TypeOf(addr), mask, reflect.TypeOf(mask))
		if rr, ok := r.Value.(*Region); ok {
			return rr, nil
		} else {
			return nil, MyError.NewError(MyError.ERROR_NOTVALID, "Found result but not valid,need check !")
		}
	} else if addr != DefaultRadixNetaddr && mask != DefaultRadixNetMask {
		return RT.GetRegionFromCacheWithAddr(DefaultRadixNetaddr, DefaultRadixNetMask)
	}
	return nil, MyError.NewError(MyError.ERROR_NOTFOUND, "Not found search region "+string(addr)+":"+string(mask))
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:16,代码来源:domain.go

示例9: GetIPinfoWithString

func GetIPinfoWithString(ip string) (Ipinfo, *MyError.MyError) {
	if ipdb := Il_open(DBFile); ipdb > 0 {
		defer Il_close(ipdb)
		nip := NewIp(ip)
		defer DeleteIp(nip)
		ipinfo := NewIpinfo()
		//		defer DeleteIpinfo(ipinfo)  "Can not delete ip info within this func!
		n := Il_search(nip, ipinfo, ipdb)
		if n > 0 {
			return ipinfo, nil
		}
	} else {
		return nil, MyError.NewError(MyError.ERROR_UNKNOWN, "Open ipdb file error :"+DBFile)
	}

	return nil, MyError.NewError(MyError.ERROR_NORESULT, "Can not get ipinfo with ip :"+ip)
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:17,代码来源:iplookup_ext.go

示例10: ParseEdnsIPNet

//ParseEdnsIPNet, Parse ends data to *net.IPNet
func ParseEdnsIPNet(ip net.IP, mask uint8, family uint16) (*net.IPNet, *MyError.MyError) {
	cidr := strings.Join([]string{ip.String(), strconv.Itoa(int(mask))}, "/")
	_, ipnet, e := net.ParseCIDR(cidr)
	if e == nil {
		return ipnet, nil
	}
	return nil, MyError.NewError(MyError.ERROR_NOTVALID, e.Error())
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:9,代码来源:utils.go

示例11: Less

func (a *Domain) Less(b llrb.Item) bool {
	if x, ok := b.(*DomainNode); ok {
		return a.DomainName < x.DomainName
	} else if y, ok := b.(*Domain); ok {
		return a.DomainName < y.DomainName
	}
	panic(MyError.NewError(MyError.ERROR_PARAM, "Param error of b "))
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:8,代码来源:domain.go

示例12: GetDomainNodeFromCacheWithName

func (DT *DomainRRTree) GetDomainNodeFromCacheWithName(d string) (*DomainNode, *MyError.MyError) {
	if _, ok := dns.IsDomainName(d); ok {
		dn := &Domain{
			DomainName: dns.Fqdn(d),
		}
		return DT.GetDomainNodeFromCache(dn)
	}
	return nil, MyError.NewError(MyError.ERROR_PARAM, "Eorror param: "+reflect.ValueOf(d).String())
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:9,代码来源:domain.go

示例13: GetDomainIDFromMySQL

func (D *RR_MySQL) GetDomainIDFromMySQL(d string) (int, *MyError.MyError) {
	if e := D.DB.Ping(); e != nil {
		if ok := InitMySQL(RC_MySQLConf); ok != true {
			return 0, MyError.NewError(MyError.ERROR_UNKNOWN, "Connect MySQL Error")
		}
	}
	sql_string := "Select idDomainName From " + DomainTable + " Where DomainName=?"
	var idDomainName int
	e := D.DB.QueryRow(sql_string, dns.Fqdn(d)).Scan(&idDomainName)
	switch {
	case e == sql.ErrNoRows:
		return 0, MyError.NewError(MyError.ERROR_NOTFOUND, "Not found record for DomainName:"+d)
	case e != nil:
		return -1, MyError.NewError(MyError.ERROR_UNKNOWN, e.Error())
	default:
		//		if id,e := strconv.Atoi(idDomainName); e== nil{
		return idDomainName, nil
		//		}
	}
	return -1, MyError.NewError(MyError.ERROR_UNKNOWN, "Unknown Error!")
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:21,代码来源:query_mysql.go

示例14: UpdateDomainNode

func (DT *DomainRRTree) UpdateDomainNode(d *DomainNode) (bool, *MyError.MyError) {
	if _, ok := dns.IsDomainName(d.DomainName); ok {
		if dt, err := DT.GetDomainNodeFromCache(&d.Domain); dt != nil && err == nil {
			d.DomainRegionTree = dt.DomainRegionTree
			DT.RWMutex.Lock()
			r := DT.LLRB.ReplaceOrInsert(d)
			DT.RWMutex.Unlock()
			if r != nil {
				return true, nil

			} else {
				//Exception:see source code of "LLRB.ReplaceOrInsert"
				return true, MyError.NewError(MyError.ERROR_UNKNOWN, "Update error, but inserted")
			}
		} else {
			return false, MyError.NewError(MyError.ERROR_NOTFOUND, "DomainRRTree does not has "+reflect.ValueOf(d).String()+" or it has "+reflect.ValueOf(dt).String())
		}
	} else {
		return false, MyError.NewError(MyError.ERROR_PARAM, " Param d "+reflect.ValueOf(d).String()+" is not valid Domain instance")
	}
	return false, MyError.NewError(MyError.ERROR_UNKNOWN, "UpdateDomainNode return unknown error")
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:22,代码来源:domain.go

示例15: NewDomainNode

func NewDomainNode(d string, soakey string, t uint32) (*DomainNode, *MyError.MyError) {
	if _, ok := dns.IsDomainName(d); !ok {
		return nil, MyError.NewError(MyError.ERROR_PARAM, d+" is not valid domain name")
	}
	return &DomainNode{
		Domain: Domain{
			DomainName: dns.Fqdn(d),
			SOAKey:     soakey,
			TTL:        t,
		},
		DomainRegionTree: NewDomainRegionTree(),
	}, nil
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:13,代码来源:domain.go


注:本文中的MyError.NewError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。