Пример #1
0
// EchoHandlerFast creates fasthttp.RequestHandler for EchoServer().
func EchoHandlerFast() fasthttp.RequestHandler {
	server := echofasthttp.New("")
	server.SetHandler(EchoServer())
	return func(ctx *fasthttp.RequestCtx) {
		server.ServeHTTP(ctx)
	}
}
Пример #2
0
func (gb *Goblin) StartServer() {
	// Middleware
	gb.server.Use(mw.Logger())
	gb.server.Use(mw.Recover())

	gb.server.Static("/static", "data/static")
	gb.SetupHandler()
	gb.server.Run(fasthttp.New(":" + strconv.Itoa(gb.config.Port)))
}
Пример #3
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	data := `
defaults:
  base_uri: http://static.turfmedia.com/
sites:
  ph:
    settings:
      affiliate-id: 2a848818

    zones:
      top: banner728x90
      middle: banner728x90
banners:
  banner728x90: #skyscraper
    -
      image: turfistar/3481d796.png
      url: "http://turfistar.com/#a_aid=2a848818&a_bid=3481d796"
    -
      image: pronostic-facile/0eca889d.png
      url: "http://www.pronostic-facile.fr?a_aid=2a848818&a_bid=0eca889d"
    -
      image: gazette-turf/8d3376b4.png
      url: "http://gazette-turf.fr/#a_aid=2a848818&a_bid=8d3376b4"
`

	// data, err := ioutil.ReadFile("config.yml")
	// if err != nil {
	// 	println("File does not exist:", err.Error())
	// 	os.Exit(1)
	// }

	// data, err := Asset("config.yml")
	// if err != nil {
	// 	println("config not found:", err.Error())
	// 	os.Exit(1)
	// }

	var config Config
	if err := config.parse([]byte(data)); err != nil {
		log.Fatal(err)
	}

	// fmt.Printf("%#v\n", config)

	e := echo.New()
	e.Use(middleware.CORS())
	e.GET("/zones/:site/:id", func(c echo.Context) error {
		zone := c.Param("id")
		site := c.Param("site")
		if config.Sites[site].Zones[zone] != "" {
			c.Response().Header().Set("Cache-Control", "max-age=59")
			return c.String(http.StatusOK, getBanner(site, zone, &config))
		}
		return c.String(http.StatusNotFound, "Not Found")
	})
	e.Static("/", "ads")
	e.Run(fasthttp.New(":1323"))

}
Пример #4
0
// echov2-fasthttp
func startEchoV2Fasthttp() {
	mux := echov2.New()
	mux.Get("/hello", echov2Handler)
	mux.Run(echov2fasthttp.New(":" + strconv.Itoa(port)))
}
Пример #5
0
// 使用Fasthttp方式开启服务
func RunFasthttp(prot string) {

	Echo.Run(fasthttp.New(prot))
}
Пример #6
0
func main() {
	// 获取执行参数
	conf_path := flag.String("conf", "", "配置文件路径")
	flag.Parse()
	// 获取配置文件的路径
	base_utils.CompletePath(conf_path)

	// 初始化log日志系统
	conf, err := base_utils.ConfigInit(*conf_path)
	if err != nil {
		re_act.Error()
		os.Exit(2)
	}

	// 初始化系统日志
	re_act.InitLog(conf.MicroSer["log1"])

	// 记录系统日志
	log := types.NewSystemLog()
	log.Type = "system"
	log.Msg = "start "
	re_act.Info(log)

	// 初始化控制层
	err = handler.Init()
	if err != nil {
		fmt.Println("handler初始化失败:", err)
		os.Exit(2)
	}

	// 选择数据序列化方式 (proto , json)
	selectProto("json")

	// echo引擎
	e := echo.New()
	// 调试测试
	e.Use(mw.Logger())
	e.Use(mw.Recover())
	// 添加跨域 cors
	e.Use(mw.CORS())

	// 容器
	//e.Get("/pod", podGet)
	//e.Post("/pod", podPost)
	//e.Put("/pod", podPut)
	//e.Patch("/pod", podPatch)
	//e.Delete("/pod", podDelete)

	// 容器网络
	//e.Get("/ser", podGet)
	//e.Post("/ser", podPost)
	//e.Put("/ser", podPut)
	//e.Patch("/ser", podPatch)
	//e.Delete("/ser", podDelete)

	// 应用
	e.Get("/app", appGet)
	e.Post("/app", appPost)
	e.Put("/app", podPut)
	e.Patch("/app", podPatch)
	e.Delete("/app", podDelete)

	// 应用模板
	e.Get("/app/temp", appTempGet)
	//e.Post("/app/temp", podPost)
	//e.Put("/app/temp", podPut)
	//e.Patch("/app/temp", podPatch)
	//e.Delete("/app/temp", podDelete)

	// 用户
	e.Get("/user", podGet)
	e.Post("/user", podPost)
	e.Put("/user", podPut)
	e.Patch("/user", podPatch)
	e.Delete("/user", podDelete)

	// 服务信息
	e.Get("/version", version)
	e.Get("/info", info)
	e.Get("/api/map", info)

	// 运行http服务器
	e.Run(fasthttp.New(":1234"))
}
Пример #7
0
func main() {
	app := echo.New()
	// create new Studio
	utils.ST = badactor.NewStudio(1024) // studio capacity... RAM?

	// add the rule to the stack
	utils.ST.AddRule(mw.LoginRule)
	err := utils.ST.CreateDirectors(1024)
	if err != nil {
		log.Fatal(err)
	}

	//poll duration
	dur := time.Minute * time.Duration(60)
	// Start the reaper
	utils.ST.StartReaper(dur)

	app.Use(middleware.Recover())
	app.Use(middleware.Gzip())
	app.Use(middleware.Secure())
	app.Use(middleware.BodyLimit("100K"))

	api := app.Group("/api")

	if config.Mode == "dev" {
		// Enable Debug
		app.Use(middleware.Logger())
		app.SetDebug(true)
		corsEnabled := middleware.CORSWithConfig(middleware.CORSConfig{
			AllowHeaders: []string{
				echo.HeaderOrigin,
				echo.HeaderContentType,
				echo.HeaderAcceptEncoding,
				echo.HeaderAuthorization,
			},
		})
		// Enable CORS /
		app.Use(corsEnabled)
		// Enable CORS /api
		api.Use(corsEnabled)
	}

	// admin routing
	// app.Static("/admin", "public/admin")
	app.Static("/admin/assets", "public/admin/assets")
	app.Static("/tinymce", "public/tinymce")
	app.File("/admin*", "public/admin/index.html")
	app.File("/admin/*", "public/admin/index.html")

	// Public
	// Setup Theme
	theme.Setup(app, config.Mode)

	users := controllers.UsersController{}
	app.POST("/auth/login", users.Login, mw.Jailer)
	app.POST("/auth/delegation", users.Delegate)

	// Get jwt signingkey
	signingKey, err := models.GetSettingString("admin_signingkey")
	if err != nil {
		panic(err)
	}
	// get api routes
	api.Use(middleware.JWT([]byte(signingKey)))

	APIRoutes(api)

	// ======= SITES =====
	site := controllers.SiteController{}
	app.GET("/", site.Home)
	app.GET("/:slug", site.Single)
	app.GET("/sitemap.xml", site.Sitemap)

	app.Run(fasthttp.New(config.Port))
}