2019-12-18 11:26:20 +01:00
/ *
* Copyright ( c ) 2019 Alex aka mailoman < alex @ webz . asia >
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an "AS IS" BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*
* @ author Alex aka mailoman < alex @ webz . asia >
* @ copyright Copyright ( c ) 2019 Alex aka mailoman < alex @ webz . asia >
* @ since 18.12 .2019
*
* /
2018-09-05 14:06:30 +02:00
package main
import (
2019-12-18 11:26:20 +01:00
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
2022-08-25 09:31:53 +02:00
"git.webz.asia/echo-go/echoswagger"
2018-09-05 14:06:30 +02:00
)
func main ( ) {
e := initServer ( ) . Echo ( )
e . Logger . Fatal ( e . Start ( ":1323" ) )
}
func initServer ( ) echoswagger . ApiRoot {
e := echo . New ( )
2019-12-18 11:26:20 +01:00
e . Use ( middleware . Recover ( ) )
e . Use ( middleware . Logger ( ) )
2019-05-11 16:27:52 +02:00
se := echoswagger . New ( e , "doc/" , & echoswagger . Info {
2018-09-05 14:06:30 +02:00
Title : "Swagger Petstore" ,
Description : "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters." ,
Version : "1.0.0" ,
TermsOfService : "http://swagger.io/terms/" ,
Contact : & echoswagger . Contact {
Email : "apiteam@swagger.io" ,
} ,
License : & echoswagger . License {
Name : "Apache 2.0" ,
URL : "http://www.apache.org/licenses/LICENSE-2.0.html" ,
} ,
} )
se . AddSecurityOAuth2 ( "petstore_auth" , "" , echoswagger . OAuth2FlowImplicit ,
"http://petstore.swagger.io/oauth/dialog" , "" , map [ string ] string {
"write:pets" : "modify pets in your account" ,
"read:pets" : "read your pets" ,
} ,
) . AddSecurityAPIKey ( "api_key" , "" , echoswagger . SecurityInHeader )
se . SetExternalDocs ( "Find out more about Swagger" , "http://swagger.io" ) .
SetResponseContentType ( "application/xml" , "application/json" ) .
2019-05-13 04:10:24 +02:00
SetUI ( echoswagger . UISetting { DetachSpec : true , HideTop : true } ) .
2018-09-16 10:35:29 +02:00
SetScheme ( "https" , "http" )
2018-09-05 14:06:30 +02:00
PetController { } . Init ( se . Group ( "pet" , "/pet" ) )
StoreController { } . Init ( se . Group ( "store" , "/store" ) )
UserController { } . Init ( se . Group ( "user" , "/user" ) )
return se
}