Beispiel #1
0
// 程序的主入口
func main() {
	flag.Parse()
	to := new(TcpObj)
	to.Type = *contentType
	to.Header = make(map[string]string)

	// 分析 Header
	switch {
	// 从文件读取
	case !z.IsBlank(*headerf):
		str, _ := z.Utf8f(z.Ph(*headerf))
		z.JsonFromString(str, &to.Header)
	// 来自参数
	case !z.IsBlank(*header):
		z.JsonFromString(*header, &to.Header)
	}

	// 分析 cookie
	switch {
	// 从文件读取
	case !z.IsBlank(*cookief):
		to.Cookie, _ = z.Utf8f(*cookief)
	// 来自参数
	default:
		to.Cookie = *cookie
	}

	// 请求体的内容,考虑 -body 或者 -f
	to.Body = *body
	if len(*file) > 0 {
		f, err := os.Open(z.Ph(*file))
		if nil != err {
			panic(err)
		}
		to.File = f
	}

	// 分析输出方式
	switch *out {
	case "all":
		to.OutputRequest = true
		to.OutputResponse = true
	case "req":
		to.OutputRequest = true
	case "resp":
		to.OutputResponse = true
	}

	// 执行
	switch {
	// 发送 HTTP 请求
	case !z.IsBlank(*httpUrl):
		to.Target = *httpUrl
		to.DoHttp()
	// 默认,打印参数说明
	default:
		flag.PrintDefaults()
	}

}
Beispiel #2
0
// 配备并重新组合查询语句, 给出QCnd对象
func (qb *QWBuilder) evalQCnd(fld string) *QCnd {
	for _, rule := range qb.Rules {
		if rule.Regex.MatchString(fld) {
			z.DebugPrintf("fld [%s] match regex [%s]\n", fld, rule.Regex.String())
			groups := rule.Regex.FindStringSubmatch(fld)
			for _, grp := range groups {
				z.DebugPrintf("    g_%s\n", grp)
			}
			extractStr := z.Trim(findMatchStr(rule.Seg, groups))
			// 生成QCnd
			qc := new(QCnd)
			qc.Key = rule.Key
			qc.Origin = fld
			qc.Plain = extractStr
			qc.Type = rule.Type
			switch qc.Type {
			case String:
				qc.Value = extractStr
			case Regex:
				qc.Value = regexp.MustCompile(extractStr)
			case IntRegion, LongRegion, DateRegion:
				qc.Value = z.MakeRegion(extractStr)
			case StringEnum:
				senum := extractStr[1 : len(extractStr)-1]
				qc.Value = z.SplitIgnoreBlank(senum, ",")
			case IntEnum:
				ienum := extractStr[1 : len(extractStr)-1]
				iarray := make([]int, 0, 5)
				for _, ie := range z.SplitIgnoreBlank(ienum, ",") {
					ione, _ := strconv.Atoi(ie)
					iarray = append(iarray, ione)
				}
				qc.Value = iarray
			case Json:
				jmap := new(map[string]interface{})
				jerr := z.JsonFromString(extractStr, jmap)
				if jerr != nil {
					qc.Value = jmap
				}
			default:
				// unsupport
				qc.Value = nil
			}
			return qc
		}
	}
	z.DebugPrintf("fld [%s] miss match\n", fld)
	return nil
}