本文整理匯總了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)
}
示例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))
}
示例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))
}
示例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)
}
示例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)
}
示例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)
}
示例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))
}
示例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)
}
示例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))
}
示例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))
}
示例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)
}
示例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)
}
示例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))
}