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


Golang swagger.InstallSwaggerService函数代码示例

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


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

示例1: main

func main() {

	//on initialise nos routes
	todo := Todo{}
	todo.InitTodo()

	var err error

	session, err = r.Connect(r.ConnectOpts{
		Address:  "localhost:28015",
		Database: "Todolist",
	})
	createDbAndTables()

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

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

		// Optionally, specifiy where the UI is located
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "swagger-ui/dist"}

	swagger.InstallSwaggerService(config)
	http.ListenAndServe(":9000", nil)
}
开发者ID:Fantasim,项目名称:Langage-Go,代码行数:30,代码来源:main.go

示例2: main

func main() {
	log.Print("[landskape] service startup...")
	flag.Parse()
	props, _ := properties.Load(*propertiesFile)
	session, _ := mgo.Dial(props["mongo.connection"]) // TODO error checking
	defer session.Close()

	appDao := dao.SystemDao{session.DB(props["mongo.database"]).C("systems")}
	conDao := dao.ConnectionDao{session.DB(props["mongo.database"]).C("connections")}
	application.SharedLogic = application.Logic{appDao, conDao}

	webservice.SystemResource{application.SharedLogic}.Register()
	webservice.ConnectionResource{application.SharedLogic}.Register()

	// graphical diagrams
	restful.Add(webservice.NewDiagramService())
	webservice.DotConfig["binpath"] = props["dot.path"]
	webservice.DotConfig["tmp"] = props["dot.tmp"]

	// expose api using swagger
	basePath := "http://" + props["http.server.host"] + ":" + props["http.server.port"]
	config := swagger.Config{
		WebServicesUrl:  basePath,
		ApiPath:         props["swagger.api"],
		SwaggerPath:     props["swagger.path"],
		SwaggerFilePath: props["swagger.home"],
		WebServices:     restful.RegisteredWebServices()}
	swagger.InstallSwaggerService(config)

	log.Printf("[landskape] ready to serve on %v\n", basePath)
	log.Fatal(http.ListenAndServe(":"+props["http.server.port"], nil))
}
开发者ID:emicklei,项目名称:landskape,代码行数:32,代码来源:launcher.go

示例3: main

func main() {
	// Swagger configuration
	SWAGGERPATH = PROPS.GetString("swagger.path", "")
	LINKERICON = filepath.Join(SWAGGERPATH, "images/mora.ico")

	// New, shared session manager, seprate DAO layer
	MONGOALIAS = PROPS.GetString("db.alias", "dev")
	sessMng := session.NewSessionManager(PROPS.FilterPrefix("mongod."), MONGOALIAS)
	defer sessMng.CloseAll()
	dao.DAO = &dao.Dao{SessMng: sessMng, MongoAlias: MONGOALIAS}
	common.UTIL = &common.Util{Props: PROPS}

	// accept and respond in JSON unless told otherwise
	restful.DefaultRequestContentType(restful.MIME_JSON)
	restful.DefaultResponseContentType(restful.MIME_JSON)
	// gzip if accepted
	restful.DefaultContainer.EnableContentEncoding(true)
	// faster router
	restful.DefaultContainer.Router(restful.CurlyRouter{})
	// no need to access body more than once
	restful.SetCacheReadEntity(false)
	// API Cross-origin requests
	apiCors := PROPS.GetBool("http.server.cors", false)

	//UserMgmt API
	usermgmt.Register(restful.DefaultContainer, apiCors)

	hostname, err := os.Hostname()
	if err != nil {
		logrus.Errorf("get hostname err is %+v", err)
	}
	endpoint := hostname + ":" + PROPS.MustGet("http.server.port")

	basePath := "http://" + PROPS.MustGet("http.server.host") + ":" + PROPS.MustGet("http.server.port")
	// Register Swagger UI
	swagger.InstallSwaggerService(swagger.Config{
		WebServices:     restful.RegisteredWebServices(),
		WebServicesUrl:  "http://" + endpoint,
		ApiPath:         "/apidocs.json",
		SwaggerPath:     SWAGGERPATH,
		SwaggerFilePath: PROPS.GetString("swagger.file.path", ""),
	})

	// If swagger is not on `/` redirect to it
	if SWAGGERPATH != "/" {
		http.HandleFunc("/", index)
	}
	// Serve favicon.ico
	http.HandleFunc("/favion.ico", icon)
	logrus.Infof("ready to serve on %s", basePath)

	logrus.Fatal(http.ListenAndServe(PROPS.MustGet("http.server.host")+":"+PROPS.MustGet("http.server.port"), nil))

}
开发者ID:popsuper1982,项目名称:DCOS_Cluster,代码行数:54,代码来源:main.go

示例4: initSwagger

func initSwagger() {
	config := swagger.Config{
		WebServices:    restful.RegisteredWebServices(), // you control what services are visible
		WebServicesUrl: "http://einvite.cloudapp.net",   //should come from config
		ApiPath:        "/api-docs",

		// Optionally, specifiy where the UI is located
		SwaggerPath:     "/docs/",
		SwaggerFilePath: "api/swagger-ui"}
	swagger.InstallSwaggerService(config)
}
开发者ID:mfelicio,项目名称:go-einvite-ddd-cqrs-es,代码行数:11,代码来源:main.go

示例5: main

func main() {
	OrderResource{}.Register()

	config := swagger.Config{
		WebServicesUrl:  "http://localhost:8080",
		ApiPath:         "/apidocs.json",
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "/Users/emicklei/Downloads/swagger-ui-1.1.7",
		WebServices:     restful.RegisteredWebServices()} // you control what services are visible
	swagger.InstallSwaggerService(config)

	http.ListenAndServe(":8080", nil)
}
开发者ID:brocaar,项目名称:go-restful,代码行数:13,代码来源:orderresource.go

示例6: main

func main() {
	log.Printf("------------------------------------------------------------------------------------------------------------------------")
	log.Printf("Starting server  API Version = %s at root %s", util.GetConfig().ApiVersion, util.GetConfig().RootPath)
	log.Printf("------------------------------------------------------------------------------------------------------------------------")
	/* Process command line arguments*/
	util.ReadFlags()
	sysConfig := util.GetConfig()
	//TODO: add Container and collection for microservices set root path and version?
	// Register User Micro Service
	mus := microrest.NewMicroUserSvc()
	mus.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/user")
	mus.MicroSvc.AddModel(model.UserModel{})
	//page
	mps := microrest.NewMicroPageSvc()
	mps.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/page")
	mps.MicroSvc.AddModel(model.PageModel{})
	//section
	mss := microrest.NewMicroSectionSvc()
	mss.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/section")
	mss.MicroSvc.AddModel(model.SectionModel{})
	//revision
	mrs := microrest.NewMicroRevisionSvc()
	mrs.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/revision")
	mrs.MicroSvc.AddModel(model.RevisionModel{})
	mrs.MicroSvc.AddRelationship(reflect.TypeOf(dto.Tag{}), model.TagRevisionModel{})
	mrs.MicroSvc.AddRelationship(reflect.TypeOf(dto.Rating{}), model.RatingModel{})
	//tag
	mts := microrest.NewMicroTagSvc()
	mts.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/tag")
	mts.MicroSvc.AddModel(model.TagModel{})

	//TODO: need to put url and swagger locations in config
	config := swagger.Config{
		WebServices:    restful.RegisteredWebServices(), // you control what services are visible
		WebServicesUrl: sysConfig.Swagger_WebServicesUrl + ":" + sysConfig.Port,
		//WebServicesUrl: "http://localhost:8686",
		ApiPath: "/apidocs.json",

		// Optionally, specifiy where the UI is located
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: sysConfig.SwaggerFilePath}
	//SwaggerFilePath: "/Users/skircher/CodeProjects/go/src/swagger-ui/dist"}

	swagger.InstallSwaggerService(config)

	http.ListenAndServe(":"+sysConfig.Port, nil)
}
开发者ID:sguzwf,项目名称:mertiwiki,代码行数:47,代码来源:wikiServer.go

示例7: main

func main() {
	restful.Add(NewUserService())

	// 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{
		WebServicesUrl:  "http://localhost:8080",
		ApiPath:         "/apidocs.json",
		SwaggerPath:     "/apidocs/",
		SwaggerFilePath: "/Users/emicklei/Downloads/swagger-ui-1.1.7",
		WebServices:     restful.RegisteredWebServices()} // you control what services are visible
	swagger.InstallSwaggerService(config)

	log.Printf("start listening on localhost:8080")
	log.Fatal(http.ListenAndServe(":8080", nil))
}
开发者ID:brocaar,项目名称:go-restful,代码行数:17,代码来源:restful-user-service.go

示例8: init

func init() {
	u := UserService{}
	u.Register()

	// 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 <your_app_id>.appspot.com/apidocs and enter http://<your_app_id>.appspot.com/apidocs.json in the api input field.
	config := swagger.Config{
		WebServices:    restful.RegisteredWebServices(), // you control what services are visible
		WebServicesUrl: getGaeURL(),
		ApiPath:        "/apidocs.json",

		// Optionally, specifiy where the UI is located
		SwaggerPath: "/apidocs/",
		// GAE support static content which is configured in your app.yaml.
		// This example expect the swagger-ui in static/swagger so you should place it there :)
		SwaggerFilePath: "static/swagger"}
	swagger.InstallSwaggerService(config)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:19,代码来源:restful-user-service.go

示例9: main

func main() {
	u := UserService{map[string]User{}}
	u.Register()

	// 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:    restful.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/Projects/swagger-ui/dist"}
	swagger.InstallSwaggerService(config)

	log.Printf("start listening on localhost:8080")
	log.Fatal(http.ListenAndServe(":8080", nil))
}
开发者ID:gtarcea,项目名称:1DevDayTalk2014,代码行数:20,代码来源:restful-user-service.go

示例10: main

func main() {
	s := reader.NewStore("data")
	defer s.Close()
	r := reader.NewRss(s)
	defer r.Close()

	registerStaticFiles()
	registerFeedService(service{s, r})

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

	log.Printf("start listening on localhost:8080")
	log.Fatal(http.ListenAndServe(":8080", nil))
}
开发者ID:jwiklund,项目名称:reader,代码行数:20,代码来源:restful.go

示例11: init

func init() {

	u := EventService{}
	u.Register()

	file, e := ioutil.ReadFile("./config.json")
	if e != nil {
		fmt.Printf("File error: %v\n", e)
		os.Exit(1)
	}

	var jsontype jsonobject
	json.Unmarshal(file, &jsontype)

	twilioAccountSid = jsontype.Twilio.Sid
	twilioAuthToken = jsontype.Twilio.Token
	twilioFrom = jsontype.Twilio.From
	twilioTo = jsontype.Twilio.To

	//fmt.Printf("Results: %v\n", jsontype)

	log.Printf("Results: %v\n", jsontype)

	// 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 <your_app_id>.appspot.com/apidocs and enter http://<your_app_id>.appspot.com/apidocs.json in the api input field.
	config := swagger.Config{
		WebServices:    restful.RegisteredWebServices(), // you control what services are visible
		WebServicesUrl: getGaeURL(),
		ApiPath:        "/apidocs.json",

		// Optionally, specifiy where the UI is located
		SwaggerPath: "/apidocs/",
		// GAE support static content which is configured in your app.yaml.
		// This example expect the swagger-ui in static/swagger so you should place it there :)
		SwaggerFilePath: "static/swagger",
	}
	swagger.InstallSwaggerService(config)
}
开发者ID:justingrammens,项目名称:devfestmn,代码行数:39,代码来源:devfest.go

示例12: init

func init() {
	u := ProfileApi{Path: "/profiles"}
	u.register()

	// 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 <your_app_id>.appspot.com/apidocs and enter
	// Place the Swagger UI files into a folder called static/swagger if you wish to use Swagger
	// http://<your_app_id>.appspot.com/apidocs.json in the api input field.
	// For testing, you can use http://localhost:8080/apidocs.json
	config := swagger.Config{
		// You control what services are visible
		WebServices:    restful.RegisteredWebServices(),
		WebServicesUrl: gaeUrl(),
		ApiPath:        "/apidocs.json",

		// Optionally, specifiy where the UI is located
		SwaggerPath: "/apidocs/",

		// GAE support static content which is configured in your app.yaml.
		// This example expect the swagger-ui in static/swagger so you should place it there :)
		SwaggerFilePath: "static/swagger"}
	swagger.InstallSwaggerService(config)
}
开发者ID:CNDonny,项目名称:scope,代码行数:24,代码来源:main.go

示例13: main

// 程序入口点
func main() {
	//通过二进制文件名,加载同名配置文件
	filePath, _ := exec.LookPath(os.Args[0])
	fileName := filepath.Base(filePath)
	idx := strings.LastIndex(fileName, ".")
	fileName = fileName[0:idx]
	flag.Set("config", fileName+".properties")

	flag.Parse()

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

	// Swagger configuration
	SwaggerPath = props.GetString("swagger.path", "")
	MoraIcon = filepath.Join(SwaggerPath, "images/mora.ico")

	// New, shared session manager
	sessMng := session.NewSessionManager(props.FilterPrefix("mongod."))
	defer sessMng.CloseAll()

	// accept and respond in JSON unless told otherwise
	restful.DefaultRequestContentType(restful.MIME_JSON)
	restful.DefaultResponseContentType(restful.MIME_JSON)
	// gzip if accepted
	restful.DefaultContainer.EnableContentEncoding(true)
	// faster router
	restful.DefaultContainer.Router(restful.CurlyRouter{})
	// no need to access body more than once
	restful.SetCacheReadEntity(false)

	// 获取配置文件中是否允许cors的变量值
	apiCors := props.GetBool("http.server.cors", false)

	// 注册API(Documents API)
	documents.Register(sessMng, restful.DefaultContainer, apiCors)

	// 如果启用了统计类API(Statistics API)
	if ok := props.GetBool("mora.statistics.enable", false); ok {
		statistics.Register(sessMng, restful.DefaultContainer)
	}

	// 要监听的服务器IP:端口
	addr := props.MustGet("http.server.host") + ":" + props.MustGet("http.server.port")
	basePath := "http://" + addr

	// Register Swagger UI
	swagger.InstallSwaggerService(swagger.Config{
		WebServices:     restful.RegisteredWebServices(),
		WebServicesUrl:  basePath,
		ApiPath:         "/apidocs.json",
		SwaggerPath:     SwaggerPath,
		SwaggerFilePath: props.GetString("swagger.file.path", ""),
	})

	// If swagger is not on `/` redirect to it
	if SwaggerPath != "/" {
		http.HandleFunc("/", index)
	}

	// Serve favicon.ico
	http.HandleFunc("/favion.ico", icon)

	info("ready to serve on %s", basePath)
	log.Fatal(http.ListenAndServe(addr, nil))
}
开发者ID:HstarStudio,项目名称:mora,代码行数:71,代码来源:main.go


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