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


Golang swagger.RegisterSwaggerService函数代码示例

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


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

示例1: main

func main() {
	flag.Parse()

	log.Printf("using store: %s\n", storePath)

	store := libmachine.NewFilestore(storePath, "", "")

	m, err := libmachine.New(store)
	if err != nil {
		log.Fatal(err)
	}

	mcn = m

	wsContainer := restful.NewContainer()
	h := HostResource{}
	h.Register(wsContainer)

	config := swagger.Config{
		WebServices:     wsContainer.RegisteredWebServices(),
		WebServicesUrl:  "http://localhost:8080",
		ApiPath:         "/apidocs.json",
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "swagger"}

	swagger.RegisterSwaggerService(config, wsContainer)

	log.Printf("start listening on localhost:8080")
	server := &http.Server{Addr: ":8080", Handler: wsContainer}
	log.Fatal(server.ListenAndServe())
}
开发者ID:carriercomm,项目名称:machine-server,代码行数:31,代码来源:main.go

示例2: main

func main() {
	// to see what happens in the package, uncomment the following
	//restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile))

	wsContainer := restful.NewContainer()
	u := UserResource{map[string]User{}}
	u.Register(wsContainer)

	// Optionally, you can install the Swagger Service which provides a nice Web UI on your REST API
	// You need to download the Swagger HTML5 assets and change the FilePath location in the config below.
	// Open http://localhost:8080/apidocs and enter http://localhost:8080/apidocs.json in the api input field.
	config := swagger.Config{
		WebServices:    wsContainer.RegisteredWebServices(), // you control what services are visible
		WebServicesUrl: "http://localhost:8080",
		ApiPath:        "/apidocs.json",

		// Optionally, specifiy where the UI is located
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "/Users/emicklei/xProjects/swagger-ui/dist"}
	swagger.RegisterSwaggerService(config, wsContainer)

	log.Printf("start listening on localhost:8080")
	server := &http.Server{Addr: ":8080", Handler: wsContainer}
	log.Fatal(server.ListenAndServe())
}
开发者ID:luxas,项目名称:flannel,代码行数:25,代码来源:restful-user-resource.go

示例3: runRestAPI

func runRestAPI(wsContainer *restful.Container) {
	config := swagger.Config{
		WebServices:     wsContainer.RegisteredWebServices(),
		WebServicesUrl:  "/", // host + port,
		ApiPath:         "/forewind/security.json",
		SwaggerPath:     "/forewind/doc/",
		SwaggerFilePath: "./dist",
		// TODO set it Title:           "libsecurity-go",
		// TODO set it Description:     "The libsecurity-go tool is for",
	}

	swagger.RegisterSwaggerService(config, wsContainer)
	if *generateJSONFlag {
		go generateJSON(config.ApiPath, config.SwaggerFilePath+"/")
	}
	log.Printf("start listening on %v", *host)
	var err error
	if strings.HasPrefix(strings.ToLower(*protocol), httpsStr) {
		err = http.ListenAndServeTLS(*host, *sslServerCert, *sslServerKey, wsContainer)
	} else {
		err = http.ListenAndServe(*host, wsContainer)
	}
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:ibm-security-innovation,项目名称:libsecurity-go,代码行数:26,代码来源:libsecurity.go

示例4: InstallSwaggerAPI

// InstallSwaggerAPI installs the /swaggerapi/ endpoint to allow schema discovery
// and traversal.  It is optional to allow consumers of the Kubernetes master to
// register their own web services into the Kubernetes mux prior to initialization
// of swagger, so that other resource types show up in the documentation.
func (m *Master) InstallSwaggerAPI() {
	hostAndPort := m.externalHost
	protocol := "https://"

	// TODO: this is kind of messed up, we should just pipe in the full URL from the outside, rather
	// than guessing at it.
	if len(m.externalHost) == 0 && m.clusterIP != nil {
		host := m.clusterIP.String()
		if m.publicReadWritePort != 0 {
			hostAndPort = net.JoinHostPort(host, strconv.Itoa(m.publicReadWritePort))
		} else {
			// Use the read only port.
			hostAndPort = net.JoinHostPort(host, strconv.Itoa(m.publicReadOnlyPort))
			protocol = "http://"
		}
	}
	webServicesUrl := protocol + hostAndPort

	// Enable swagger UI and discovery API
	swaggerConfig := swagger.Config{
		WebServicesUrl:  webServicesUrl,
		WebServices:     m.handlerContainer.RegisteredWebServices(),
		ApiPath:         "/swaggerapi/",
		SwaggerPath:     "/swaggerui/",
		SwaggerFilePath: "/swagger-ui/",
	}
	swagger.RegisterSwaggerService(swaggerConfig, m.handlerContainer)
}
开发者ID:cjnygard,项目名称:origin,代码行数:32,代码来源:master.go

示例5: enableSwagger

func enableSwagger() {
	config := swagger.Config{
		WebServices:     restful.DefaultContainer.RegisteredWebServices(), // you control what services are visible
		ApiPath:         "/apidocs.json",
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "swagger-ui/"}
	swagger.RegisterSwaggerService(config, restful.DefaultContainer)
}
开发者ID:rutchkiwi,项目名称:go-rest-api,代码行数:8,代码来源:main.go

示例6: initSwagger

func (a *Application) initSwagger() {
	swconfig := swagger.Config{
		WebServices:     a.Container.RegisteredWebServices(),
		WebServicesUrl:  a.Config.Get("swagger.ws_url").(string),
		ApiPath:         a.Config.Get("swagger.api_path").(string),
		SwaggerPath:     a.Config.Get("swagger.url").(string),
		SwaggerFilePath: a.Config.Get("swagger.file_path").(string),
	}
	swagger.RegisterSwaggerService(swconfig, a.Container)
}
开发者ID:johnwilson,项目名称:restapi,代码行数:10,代码来源:core.go

示例7: Swagger

func Swagger(wsContainer *restful.Container, apiPath, swaggerPath, swaggerFilepath string) {
	config := swagger.Config{
		WebServices: wsContainer.RegisteredWebServices(), // you control what services are visible
		ApiPath:     apiPath,

		// Optionally, specifiy where the UI is located
		SwaggerPath:     swaggerPath,
		SwaggerFilePath: swaggerFilepath,
	}
	swagger.RegisterSwaggerService(config, wsContainer)
}
开发者ID:iwarsong,项目名称:bearded,代码行数:11,代码来源:swagger.go

示例8: main

func main() {
	flag.Parse()

	log.Printf("loading configuration from [%s]", *propertiesFile)
	var err error
	if props, err = properties.LoadFile(*propertiesFile, properties.UTF8); err != nil {
		log.Fatalf("[soysos][error] Unable to read properties:%v\n", err)
	}

	addr := props.MustGet("http.server.host") + ":" + props.MustGet("http.server.port")
	basePath := "http://" + addr
	SwaggerPath = props.GetString("swagger.path", "")

	cmap := make(map[string]CatFact)
	cmap["Lion"] = CatFact{"", "Lion", "Lions have sharp teef :D"}

	cat := CatResource{cmap}
	root := RootResource{SwaggerPath}
	user := UserResource{}

	wsContainer := restful.NewContainer()
	wsContainer.Filter(GlobalLogging)
	wsContainer.Filter(enableCORS)

	restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile))
	cat.Register(wsContainer)
	root.Register(wsContainer)
	user.Register(wsContainer)

	config := swagger.Config{
		WebServices:     wsContainer.RegisteredWebServices(),
		WebServicesUrl:  basePath,
		ApiPath:         "/apidocs.json",
		SwaggerPath:     SwaggerPath,
		SwaggerFilePath: props.GetString("swagger.file.path", "")}

	swagger.RegisterSwaggerService(config, wsContainer)

	cors := restful.CrossOriginResourceSharing{
		AllowedHeaders: []string{"Accept", "Authorization"},
		AllowedMethods: []string{"GET"},
		CookiesAllowed: false,
		Container:      wsContainer}

	//wsContainer.Filter(wsContainer.OPTIONSFilter)
	wsContainer.Filter(cors.Filter)

	server := &http.Server{Addr: addr, Handler: wsContainer}

	log.Printf("start listening on %s", basePath)

	log.Fatal(server.ListenAndServe())
}
开发者ID:abhiunc,项目名称:soysos,代码行数:53,代码来源:main.go

示例9: main

func main() {

	datastore, err := kv.Open("mpush.kvdb", &kv.Options{})

	if err != nil {
		log.Fatal(err)
	}
	defer datastore.Close()

	wsContainer := restful.NewContainer()

	restful.Filter(globalLogging)

	dsl := DistributionListResource{datastore}
	dsl.Register(wsContainer)

	wsPush := new(restful.WebService)

	wsPush.Path("/api/push")
	wsPush.Route(wsPush.POST("").
		Consumes("application/x-www-form-urlencoded").
		To(func(request *restful.Request, response *restful.Response) { pushHandler(request, response, datastore) }).
		// docs
		Doc("push to a distribution list").
		Param(wsPush.BodyParameter("List", "list to send to").DataType("string")).
		Param(wsPush.BodyParameter("Title", "title of notification").DataType("string")).
		Param(wsPush.BodyParameter("Body", "body of notification").DataType("string")).
		Reads(PushNotification{})) // from the request
	wsContainer.Add(wsPush)

	// static files
	wsStatic := new(restful.WebService)
	wsStatic.Route(wsStatic.GET("/static/{resource}").To(staticFromPathParam))
	wsStatic.Route(wsStatic.GET("/static").To(staticFromQueryParam))
	wsContainer.Add(wsStatic)

	// Optionally, you can install the Swagger Service which provides a nice Web UI on your REST API
	// You need to download the Swagger HTML5 assets and change the FilePath location in the config below.
	// Open http://localhost:8080/apidocs and enter http://localhost:8080/apidocs.json in the api input field.
	config := swagger.Config{
		WebServices:    wsContainer.RegisteredWebServices(), // you control what services are visible
		WebServicesUrl: "http://localhost:8080",
		ApiPath:        "/apidocs.json",

		// Optionally, specifiy where the UI is located
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "/home/dgryski/work/src/cvs/swagger-ui/dist"}
	swagger.RegisterSwaggerService(config, wsContainer)

	log.Printf("start listening on localhost:8080")
	server := &http.Server{Addr: ":8080", Handler: wsContainer}
	log.Fatal(server.ListenAndServe())
}
开发者ID:pombredanne,项目名称:trifles,代码行数:53,代码来源:main.go

示例10: InstallSwaggerAPI

// InstallSwaggerAPI installs the /swaggerapi/ endpoint to allow schema discovery
// and traversal.  It is optional to allow consumers of the Kubernetes master to
// register their own web services into the Kubernetes mux prior to initialization
// of swagger, so that other resource types show up in the documentation.
func (m *Master) InstallSwaggerAPI() {
	// Enable swagger UI and discovery API
	swaggerConfig := swagger.Config{
		WebServicesUrl: m.readWriteServer,
		WebServices:    m.handlerContainer.RegisteredWebServices(),
		// TODO: Parameterize the path?
		ApiPath:         "/swaggerapi/",
		SwaggerPath:     "/swaggerui/",
		SwaggerFilePath: "/swagger-ui/",
	}
	swagger.RegisterSwaggerService(swaggerConfig, m.handlerContainer)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:16,代码来源:master.go

示例11: main

func main() {
	flag.Parse()
	// to see what happens in the package, uncomment the following
	//restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile))

	wsContainer := NewHandlerContainer()

	var application app.Application
	var err error

	// Check configuration file was given
	if configfile == "" {
		fmt.Fprintln(os.Stderr, "Please provide configuration file")
		os.Exit(1)
	}

	// Setup a new applications for common APIs

	appCollection := conf.LoadAppConfiguration(configfile)
	fmt.Println(appCollection)

	for _, element := range appCollection.Apps {
		fmt.Println("Initializing..", element)
		application, err = app.InitApp(element.Name, element.ConfigFilePath)

		err = application.SetRoutes(wsContainer)
		if err != nil {
			fmt.Println("Unable to create http server endpoints")
			os.Exit(1)
		}
	}

	// Install the Swagger Service which provides a nice Web UI on your REST API
	// You need to download the Swagger HTML5 assets and change the FilePath location in the config below.
	// Open http://localhost:8080/apidocs and enter http://localhost:8080/apidocs.json in the api input field.
	//fmt.Println("appCollection.Swagger.Status", appCollection.Swagger.Status)
	if appCollection.Swagger.Status {

		config := swagger.Config{}
		config.WebServices = wsContainer.RegisteredWebServices()
		config.WebServicesUrl = appCollection.Swagger.WebServicesUrl
		config.ApiPath = appCollection.Swagger.ApiPath
		config.SwaggerPath = appCollection.Swagger.SwaggerPath
		config.SwaggerFilePath = appCollection.Swagger.SwaggerFilePath

		swagger.RegisterSwaggerService(config, wsContainer)
	}
	log.Printf("start listening on localhost:8080")
	server := &http.Server{Addr: ":8080", Handler: wsContainer}
	log.Fatal(server.ListenAndServe())
}
开发者ID:dpmramesh,项目名称:skyring,代码行数:51,代码来源:main.go

示例12: InstallSwaggerAPI

// InstallSwaggerAPI installs the /swaggerapi/ endpoint to allow schema discovery
// and traversal. It is optional to allow consumers of the Kubernetes GenericAPIServer to
// register their own web services into the Kubernetes mux prior to initialization
// of swagger, so that other resource types show up in the documentation.
func (s *GenericAPIServer) InstallSwaggerAPI() {
	hostAndPort := s.ExternalAddress
	protocol := "https://"
	webServicesUrl := protocol + hostAndPort

	// Enable swagger UI and discovery API
	swaggerConfig := swagger.Config{
		WebServicesUrl:  webServicesUrl,
		WebServices:     s.HandlerContainer.RegisteredWebServices(),
		ApiPath:         "/swaggerapi/",
		SwaggerPath:     "/swaggerui/",
		SwaggerFilePath: "/swagger-ui/",
	}
	swagger.RegisterSwaggerService(swaggerConfig, s.HandlerContainer)
}
开发者ID:dilgerma,项目名称:scope,代码行数:19,代码来源:genericapiserver.go

示例13: StartRestAPIServer

func StartRestAPIServer() {
	registerWebServiceHistoricalReplicationControllerMetric()
	registerWebServiceHistoricalReplicationController()
	registerWebServiceHistoricalEvent()
	registerWebServiceHealthCheck()
	registerWebServiceAuditLog()
	registerWebServiceBuildLog()

	// Place the method+path to description mapping to map for audit
	for _, rws := range restful.DefaultContainer.RegisteredWebServices() {
		for _, r := range rws.Routes() {
			audit.AddDescription(r.String(), r.Doc)
		}
	}

	// You can install the Swagger Service which provides a nice Web UI on your REST API
	// You need to download the Swagger HTML5 assets and change the FilePath location in the config below.
	// Open http://localhost:8080/apidocs and enter http://localhost:8080/apidocs.json in the api input field.
	config := swagger.Config{
		WebServices: restful.DefaultContainer.RegisteredWebServices(), // you control what services are visible
		//WebServicesUrl: "http://localhost:8080",
		ApiPath: "/apidocs.json",

		// Optionally, specifiy where the UI is located
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "swaggerui"}
	swagger.RegisterSwaggerService(config, restful.DefaultContainer)

	restapiPort, ok := configuration.LocalConfiguration.GetInt("restapiPort")
	if ok == false {
		log.Error("Can't find restapiPort")
		panic("Can't find restapiPort")
	}

	server := &http.Server{Addr: ":" + strconv.Itoa(restapiPort), Handler: restful.DefaultContainer}

	certificate, ok := configuration.LocalConfiguration.GetString("certificate")
	if ok == false {
		log.Error("Can't find certificate path")
		panic("Can't find certificate path")
	}
	key, ok := configuration.LocalConfiguration.GetString("key")
	if ok == false {
		log.Error("Can't find certificate path")
		panic("Can't find key path")
	}
	server.ListenAndServeTLS(certificate, key)
}
开发者ID:cloudawan,项目名称:cloudone_analysis,代码行数:48,代码来源:restapi.go

示例14: Install

// Install adds the SwaggerUI webservice to the given mux.
func (s Swagger) Install(c *mux.APIContainer) {
	swagger.RegisterSwaggerService(swagger.Config{
		WebServicesUrl:  "https://" + s.ExternalAddress,
		WebServices:     c.RegisteredWebServices(),
		ApiPath:         "/swaggerapi/",
		SwaggerPath:     "/swaggerui/",
		SwaggerFilePath: "/swagger-ui/",
		SchemaFormatHandler: func(typeName string) string {
			switch typeName {
			case "metav1.Time", "*metav1.Time":
				return "date-time"
			}
			return ""
		},
	}, c.Container)
}
开发者ID:alex-mohr,项目名称:kubernetes,代码行数:17,代码来源:swagger.go

示例15: main

func main() {
	// to see what happens in the package, uncomment the following
	restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile))

	wsContainer := restful.NewContainer()

	// Root
	var root = resources.RootResource{}
	root.Register(wsContainer)

	// lookups
	resourcesv1.EmploymentTypesResource{}.Register(wsContainer)
	resourcesv1.TagsResource{}.Register(wsContainer)
	resourcesv1.PostsResource{}.Register(wsContainer)
	resourcesv1.ScrumTeamsResource{}.Register(wsContainer)
	resourcesv1.SprintsResource{}.Register(wsContainer)

	// Add container filter to enable CORS
	cors := restful.CrossOriginResourceSharing{
		ExposeHeaders:  []string{"X-My-Header"},
		AllowedHeaders: []string{"Content-Type"},
		CookiesAllowed: false,
		Container:      wsContainer}
	wsContainer.Filter(cors.Filter)

	// Add container filter to respond to OPTIONS
	wsContainer.Filter(wsContainer.OPTIONSFilter)

	// Optionally, you can install the Swagger Service which provides a nice Web UI on your REST API
	// You need to download the Swagger HTML5 assets and change the FilePath location in the config below.
	// Open http://localhost:8080/apidocs and enter http://localhost:8080/apidocs.json in the api input field.

	config := swagger.Config{
		WebServices:    wsContainer.RegisteredWebServices(), // you control what services are visible
		WebServicesUrl: "http://localhost:5555",
		ApiPath:        "/apidocs.json",

		// Optionally, specifiy where the UI is located
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "./swagger-ui/dist"}
	swagger.RegisterSwaggerService(config, wsContainer)

	log.Printf("start listening on localhost:5555")
	server := &http.Server{Addr: ":5555", Handler: wsContainer}
	log.Fatal(server.ListenAndServe())
}
开发者ID:marchuanv,项目名称:eNonymous,代码行数:46,代码来源:main.go


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