Exemple #1
0
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)
}
Exemple #2
0
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))
}
Exemple #3
0
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))

}
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)
}
Exemple #5
0
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)
}
Exemple #6
0
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)
}
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))
}
Exemple #8
0
func main() {

	initRoutes()
	api.InitRethinkDB()

	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)

}
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)
}
Exemple #10
0
func main() {
	// Swagger configuration
	SwaggerPath = Props.GetString("swagger.path", "")
	LinkerIcon = filepath.Join(SwaggerPath, "images/mora.ico")

	// 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)
	// Documents API
	documents.Register(restful.DefaultContainer, apiCors)

	basePath := "http://" + Props.MustGet("http.server.host") + ":" + Props.MustGet("http.server.port")
	endpoint := Hostname + ":" + 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))

	// router := NewRouter().StrictSlash(true)
	// logrus.Fatal(http.ListenAndServe(Props["http.server.host"]+":"+Props["http.server.port"], router))
}
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))
}
Exemple #12
0
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))
}
Exemple #13
0
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)
}
Exemple #14
0
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)
}
Exemple #15
0
func main() {
	// Swagger configuration
	SwaggerPath = Props.GetString("swagger.path", "")
	LinkerIcon = filepath.Join(SwaggerPath, "images/mora.ico")

	// TODO: Check mongo flag, if mongo is set by flag, using mongo flag

	fmt.Println("call deployment enabled:", Props.GetBool("call.deployment", false))

	// 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}
	fmt.Println(dao.DAO.MongoAlias)

	lbClient := common.LbClient{
		Host: Props.MustGetString("lb.host"),
	}
	common.UTIL = &common.Util{LbClient: &lbClient, 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)
	// Documents API
	documents.Register(restful.DefaultContainer, apiCors)

	// Check hostname flag, if hostname is set by flag, using hostname
	if strings.TrimSpace(Hostname) == "" {
		hostname, err := os.Hostname()
		if err != nil {
			logrus.Errorf("get hostname err is %+v", err)
		}
		Hostname = hostname
	}
	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))

	// router := NewRouter().StrictSlash(true)
	// logrus.Fatal(http.ListenAndServe(Props["http.server.host"]+":"+Props["http.server.port"], router))
}
Exemple #16
0
// 程序入口点
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))
}