• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang swagger.RegisterSwaggerService函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: New

// New creates a new Docker remote API service instance in the form of an
// http.Handler.
func New(impl api.Service, swaggerFilePath string) http.Handler {
	baseSrv := newBaseServer(impl)
	containersSrv := newContainersServer(impl)

	container := restful.NewContainer()
	container.Add(baseSrv.WebService)
	container.Add(containersSrv.WebService)

	swaggerConf := swagger.Config{
		WebServices:     container.RegisteredWebServices(),
		ApiPath:         "/docs/apidocs.json",
		SwaggerPath:     "/docs/swagger/",
		SwaggerFilePath: swaggerFilePath,
	}
	swagger.RegisterSwaggerService(swaggerConf, container)

	return container
}
开发者ID:runcom,项目名称:docker-api,代码行数:20,代码来源:server.go


示例17: StartServer

func StartServer(e *env.Env) {
	restful.SetLogger(e.Log)
	aEnv := ApiEnv{e}

	wsContainer := restful.NewContainer()

	// Enable gzip encoding
	//wsContainer.EnableContentEncoding(true)

	// Request logging
	wsContainer.Filter(aEnv.ReqLogger)

	// Route error handling
	wsContainer.ServiceErrorHandler(aEnv.WriteServiceErrorJson)

	// Register apis
	aEnv.registerUserApis(wsContainer)
	aEnv.registerPostApis(wsContainer)
	aEnv.registerVoteApis(wsContainer)

	// Some bullshit so ServiceErrorHandler works...
	errWs := new(restful.WebService)
	errWs.Path("/")
	wsContainer.Add(errWs)

	if e.SwaggerPath != "" {
		config := swagger.Config{
			WebServices:     wsContainer.RegisteredWebServices(),
			ApiPath:         "/swagger/apidocs.json",
			SwaggerPath:     "/swagger/apidocs/",
			SwaggerFilePath: e.SwaggerPath,
		}

		//Container just for swagger
		swContainer := restful.NewContainer()
		swagger.RegisterSwaggerService(config, swContainer)
		http.Handle("/swagger/", swContainer)
	}

	http.Handle("/", wsContainer)
	e.Log.Info("[server/api] start listening on localhost:" + e.ApiPort)

	e.Log.Fatal(http.ListenAndServe(":"+e.ApiPort, nil))
}
开发者ID:AnomiNet,项目名称:anomi,代码行数:44,代码来源:api.go


示例18: main

//main - Application.
func main() {

	log.Printf("Configuring container.")
	container := restful.NewContainer()
	container.Filter(filter.NCSACommonLogFormatLogger())
	container.Add(webservice.TaskWebService())

	log.Printf("Registering Swagger.")
	config := swagger.Config{
		WebServices: container.RegisteredWebServices(),
		ApiPath:     "/apidocs.json",
		ApiVersion:  "1.0",
		Info:        swagger.Info{Title: "hubertwo/go-todo", Description: "Simple TODO list manager in Go."}}
	swagger.RegisterSwaggerService(config, container)

	log.Printf("Starting server.")
	server := &http.Server{Addr: ":8080", Handler: container}
	log.Fatal(server.ListenAndServe())
}
开发者ID:HubertWo,项目名称:go-todo,代码行数:20,代码来源:main.go


示例19: 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() {
	webServicesUrl := ""
	// Use the secure read write port, if available.
	if m.publicReadWritePort != 0 {
		webServicesUrl = "https://" + net.JoinHostPort(m.publicIP.String(), strconv.Itoa(m.publicReadWritePort))
	} else {
		// Use the read only port.
		webServicesUrl = "http://" + net.JoinHostPort(m.publicIP.String(), strconv.Itoa(m.publicReadOnlyPort))
	}
	// 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:vrosnet,项目名称:kubernetes,代码行数:23,代码来源:master.go


示例20: main

func main() {
	err := config.LoadGlobalConfig()
	if err != nil {
		log.Fatalf("Failed to load config: %v", err)
	}

	go images.StartGC()
	go images.StartImageUpdate()
	// 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 := DockerResource{url: "unix:///var/run/docker.sock"}
	u.Register(wsContainer)

	wsContainer.Filter(func(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
		resp.AddHeader("Access-Control-Allow-Origin", "*")
		chain.ProcessFilter(req, resp)
	})

	wsContainer.Handle("/", http.FileServer(assetFS()))

	// 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:th3architect,项目名称:sherdock,代码行数:39,代码来源:main.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang goson.Render函数代码示例发布时间:2022-05-23
下一篇:
Golang swagger.InstallSwaggerService函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap