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


Golang Swagger.Produces方法代码示例

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


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

示例1: newSpec

func newSpec(endpoint string) *spec.Swagger {
	// TODO enable defaults
	// TODO complete swagger metadata and move to diff function
	api := new(spec.Swagger)
	api.Swagger = "2.0"
	api.BasePath = endpoint

	api.Info = new(spec.Info)
	api.Info.Version = "0.0.0"
	api.Info.Title = revel.AppName
	api.Info.Description = "Description"
	api.Info.TermsOfService = "http://swagger.io/terms/"

	api.Info.Contact = new(spec.ContactInfo)
	api.Info.Contact.Name = ""
	api.Info.Contact.Email = ""
	api.Info.Contact.URL = ""

	api.Info.License = new(spec.License)
	api.Info.License.Name = "LICENSE"
	api.Info.License.URL = "URL"

	// Now is added on requests to Swaggify.Spec

	// TODO check if https is HSTS exclusively or no for revel
	// TODO ALSO this can be SSL terminated by proxy so this may need changing
	if revel.HttpSsl {
		api.Schemes = []string{"https"}
	} else {
		api.Schemes = []string{"http"}
	}

	api.Consumes = ContentTypes
	api.Produces = ContentTypes

	// the Swagger type hoists unexported types for some annoying reason
	api.Paths = buildPaths(api.BasePath)
	api.Definitions = buildDefinitions(api.BasePath)

	return api
}
开发者ID:waiteb3,项目名称:revel-swagger,代码行数:41,代码来源:swaggify.go

示例2: metaProducesSetter

func metaProducesSetter(meta *spec.Swagger) func([]string) {
	return func(produces []string) { meta.Produces = produces }
}
开发者ID:MStoykov,项目名称:go-swagger,代码行数:3,代码来源:meta.go

示例3: Execute

// Execute this command
func (s *Spec) Execute(args []string) error {
	targetPath := "."
	if len(args) > 0 {
		targetPath = args[0]
	}
	realPath, err := filepath.Abs(targetPath)
	if err != nil {
		return err
	}
	var file *os.File
	switch s.Format {
	case "json":
		file, err = os.Create(filepath.Join(realPath, "swagger.json"))
		if err != nil {
			return err
		}
	case "yaml", "yml":
		file, err = os.Create(filepath.Join(realPath, "swagger.yml"))
		if err != nil {
			return err
		}
	default:
		return fmt.Errorf("invalid format: %s", s.Format)
	}
	defer file.Close()
	log.Println("creating specification document in", filepath.Join(targetPath, file.Name()))

	var doc spec.Swagger
	info := new(spec.Info)
	doc.Info = info

	doc.Swagger = "2.0"
	doc.Paths = new(spec.Paths)
	doc.Definitions = make(spec.Definitions)

	info.Title = s.Title
	if info.Title == "" {
		info.Title = swag.ToHumanNameTitle(filepath.Base(realPath))
	}
	info.Description = s.Description
	info.Version = s.Version
	info.TermsOfService = s.Terms
	if s.Contact.Name != "" || s.Contact.Email != "" || s.Contact.URL != "" {
		var contact spec.ContactInfo
		contact.Name = s.Contact.Name
		contact.Email = s.Contact.Email
		contact.URL = s.Contact.URL
		info.Contact = &contact
	}
	if s.License.Name != "" || s.License.URL != "" {
		var license spec.License
		license.Name = s.License.Name
		license.URL = s.License.URL
		info.License = &license
	}

	for _, cons := range s.Consumes {
		doc.Consumes = append(doc.Consumes, cons)
	}
	for _, prods := range s.Produces {
		doc.Produces = append(doc.Produces, prods)
	}
	for _, scheme := range s.Schemes {
		doc.Schemes = append(doc.Schemes, scheme)
	}

	if s.Format == "json" {
		enc := json.NewEncoder(file)
		if err := enc.Encode(doc); err != nil {
			return err
		}
		return nil
	}

	b, err := yaml.Marshal(swag.ToDynamicJSON(doc))
	if err != nil {
		return err
	}
	if _, err := file.Write(b); err != nil {
		return err
	}
	return nil
}
开发者ID:MStoykov,项目名称:go-swagger,代码行数:84,代码来源:spec.go


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