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


Golang CurlOptions.GroupedHeaders方法代码示例

本文整理汇总了Golang中github.com/shibukawa/curl_as_dsl/common.CurlOptions.GroupedHeaders方法的典型用法代码示例。如果您正苦于以下问题:Golang CurlOptions.GroupedHeaders方法的具体用法?Golang CurlOptions.GroupedHeaders怎么用?Golang CurlOptions.GroupedHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/shibukawa/curl_as_dsl/common.CurlOptions的用法示例。


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

示例1: ProcessCurlCommand

/*
	Dispatcher function of curl command
	This is an exported function and called from httpgen.
*/
func ProcessCurlCommand(options *common.CurlOptions) (string, interface{}) {
	generator := NewXHRGenerator(options)

	for i, data := range options.ProcessedData {
		fileName := data.FileName()
		if fileName != "" {
			isText := data.Type == common.DataAsciiType
			file := &ExternalFile{
				Data:     &data,
				FileName: fileName,
				TextType: isText,
			}
			generator.ExternalFiles[i] = file
		}
	}

	if len(generator.ExternalFiles) == 1 {
		for _, externalFile := range generator.ExternalFiles {
			externalFile.VariableName = "file"
		}
	} else {
		for i, externalFile := range generator.ExternalFiles {
			externalFile.VariableName = fmt.Sprintf("file_%d", i+1)
		}
	}

	generator.processedHeaders = options.GroupedHeaders()

	var templateName string
	switch len(generator.ExternalFiles) {
	case 0:
		templateName = "simple"
	case 1:
		templateName = "external_file"
	default:
		templateName = "external_files"
	}

	if generator.Options.User != "" {
		generator.specialHeaders = append(generator.specialHeaders, []string{"Authorization", fmt.Sprintf(`"Basic " + btoa("%s")`, generator.Options.User)})
	}

	if options.ProcessedData.HasData() {
		if options.Get {
			generator.SetDataForUrl()
		} else {
			generator.Options.InsertContentTypeHeader("application/x-www-form-urlencoded")
			generator.SetDataForBody()
		}
	} else if options.ProcessedData.HasForm() {
		generator.SetFormForBody()
	} else if options.Method() == "GET" && len(generator.processedHeaders) == 0 && len(generator.specialHeaders) == 0 {
	}

	return templateName, *generator
}
开发者ID:spiegel-im-spiegel,项目名称:curl_as_dsl,代码行数:60,代码来源:generator.go

示例2: ProcessCurlCommand

/*
	Dispatcher function of curl command
	This is an exported function and called from httpgen.
*/
func ProcessCurlCommand(options *common.CurlOptions) (string, interface{}) {
	generator := NewNodeJsGenerator(options)
	if options.Http2Flag {
		generator.Modules["http2"] = true
		generator.ClientModule = "http2"
	} else if strings.HasPrefix(options.Url, "https") {
		generator.Modules["https"] = true
		generator.ClientModule = "https"
	} else {
		generator.Modules["http"] = true
		generator.ClientModule = "http"
		options.Insecure = false
	}

	for _, data := range options.ProcessedData {
		fileName := data.FileName()
		if fileName != "" {
			isText := data.Type == common.DataAsciiType
			generator.ExternalFiles = append(generator.ExternalFiles, ExternalFile{FileName: fileName, TextType: isText})
		}
	}

	generator.processedHeaders = options.GroupedHeaders()

	var templateName string
	switch len(generator.ExternalFiles) {
	case 0:
		templateName = "full"
	case 1:
		templateName = "external_file"
	default:
		templateName = "external_files"
	}

	if generator.Options.User != "" {
		generator.specialHeaders = append(generator.specialHeaders, fmt.Sprintf("\"Authorization\": \"Basic \" + new Buffer(\"%s\").toString(\"base64\")", generator.Options.User))
	}

	if options.ProcessedData.HasData() {
		if options.Get {
			generator.SetDataForUrl()
		} else {
			generator.Options.InsertContentTypeHeader("application/x-www-form-urlencoded")
			generator.SetDataForBody()
		}
	} else if options.ProcessedData.HasForm() {
		generator.SetFormForBody()
	} else if options.Method() == "GET" && len(generator.processedHeaders) == 0 && len(generator.specialHeaders) == 0 {
		if templateName == "full" && !options.Insecure {
			templateName = "simple_get"
		}
	}

	return templateName, *generator
}
开发者ID:VViles,项目名称:curl_as_dsl,代码行数:59,代码来源:generator.go


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