Ejemplo n.º 1
1
func main() {
	e := echo.New()
	// the file server for rice. "app" is the folder where the files come from.
	assetHandler := http.FileServer(rice.MustFindBox("app").HTTPBox())
	// serves the index.html from rice
	e.GET("/", standard.WrapHandler(assetHandler))

	// servers other static files
	e.GET("/static/*", standard.WrapHandler(http.StripPrefix("/static/", assetHandler)))
	e.Run(standard.New(":3000"))
}
Ejemplo n.º 2
0
Archivo: gomd.go Proyecto: nochso/gomd
func main() {
	// Parse command line arguments
	kingpin.Version("0.0.1")
	kingpin.Parse()

	// Prepare (optionally) embedded resources
	templateBox := rice.MustFindBox("template")
	staticHTTPBox := rice.MustFindBox("static").HTTPBox()
	staticServer := http.StripPrefix("/static/", http.FileServer(staticHTTPBox))

	e := echo.New()

	t := &Template{
		templates: template.Must(template.New("base").Parse(templateBox.MustString("base.html"))),
	}
	e.SetRenderer(t)

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	e.GET("/static/*", standard.WrapHandler(staticServer))

	edit := e.Group("/edit")
	edit.Get("/*", EditHandler)
	edit.Post("/*", EditHandlerPost)

	go WaitForServer()
	e.Run(standard.New(fmt.Sprintf("127.0.0.1:%d", *args.Port)))
}
Ejemplo n.º 3
0
func main() {
	e := echo.New()
	e.SetDebug(true)

	// enable any filename to be loaded from in-memory file system
	e.GET("/*", standard.WrapHandler(myEmbeddedFiles.Handler))

	// read ufo.html from in-memory file system
	htmlb, err := myEmbeddedFiles.ReadFile("ufo.html")
	if err != nil {
		log.Fatal(err)
	}

	// convert to string
	html := string(htmlb)

	// serve ufo.html through "/"
	e.GET("/", func(c echo.Context) error {

		// serve it
		return c.HTML(http.StatusOK, html)
	})

	// try it -> http://localhost:1337/
	// http://localhost:1337/ufo.html
	// http://localhost:1337/public/README.md
	open.Run("http://localhost:1337/")
	e.Run(standard.New(":1337"))

}
Ejemplo n.º 4
0
func (ceh *customEchoHandler) mustWrapHandleFunc(c echo.Context) echo.HandlerFunc {
	if _, ok := c.Request().(*standard.Request); ok {
		return standard.WrapHandler(ceh.httpHandler)
	} else if _, ok = c.Request().(*fasthttp.Request); ok {
		return NewFastHTTPEchoAdaptor(ceh.httpHandler)
	}

	log.Fatal("Unknown HTTP implementation")
	return nil
}
Ejemplo n.º 5
0
func client() echo.HandlerFunc {
	clientFS := http.FileServer(
		&assetfs.AssetFS{
			Asset:     Asset,
			AssetDir:  AssetDir,
			AssetInfo: AssetInfo,
			Prefix:    "client",
		},
	)

	return standard.WrapHandler(clientFS)
}
Ejemplo n.º 6
0
// NewServer creates a new server.
func NewServer(conf ServerConfig) (*standard.Server, error) {
	if conf.RootPassword == "" {
		return nil, errors.New("missing root username")
	}

	if conf.RootPassword == "" {
		return nil, errors.New("missing root password")
	}

	if conf.Store == nil {
		return nil, errors.New("missing store")
	}

	if conf.Notifier == nil {
		conf.Notifier = notifier.NewNOOPNotifier()
	}

	e := echo.New()

	basicAuthMiddleware := AuthMiddleware(conf.RootUsername, conf.RootPassword, conf.Store)

	e.Use(TraceMiddleware())
	e.Use(LogMiddleware())
	e.Use(InstrumentMiddleware(conf.Stats))
	e.Use(middleware.Recover())

	features := NewFeatureResource(conf.Store, conf.Stats, conf.Notifier)
	environments := NewEnvironmentResource(conf.Store, conf.Stats)
	users := NewUserResource(conf.Store, conf.Stats)

	e.Get("/api/health", standard.WrapHandler(healthz.Handler()))

	e.Get("/api/features/:name", features.Get, basicAuthMiddleware)
	e.Get("/api/features", features.List, basicAuthMiddleware)
	e.Post("/api/features", features.Create, basicAuthMiddleware)
	e.Patch("/api/features/:name", features.Update, basicAuthMiddleware)

	e.Get("/api/environments/:name", environments.Get, basicAuthMiddleware)
	e.Get("/api/environments", environments.List, basicAuthMiddleware)
	e.Post("/api/environments", environments.Create, basicAuthMiddleware)
	e.Patch("/api/environments/:name", environments.Update, basicAuthMiddleware)

	e.Get("/api/users/:username", users.Get, basicAuthMiddleware)
	e.Post("/api/users", users.Create, basicAuthMiddleware)

	e.Static("/static", "public")
	e.File("/*", "public/index.html")

	server := standard.WithConfig(engine.Config{})
	server.SetHandler(e)

	return server, nil
}
Ejemplo n.º 7
0
func (this *WebsocketController) RegisterRoute(g *echo.Group) {
	g.GET("/ws", standard.WrapHandler(websocket.Handler(this.Ws)))
}
Ejemplo n.º 8
0
func InitializeWebsocket(e *echo.Echo) error {

	e.GET("/ws/:name", standard.WrapHandler(http.HandlerFunc(ws())))

	return nil
}
Ejemplo n.º 9
-1
func main() {
	e := echo.New()
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())
	e.Use(middleware.Static("../public"))
	e.GET("/ws", standard.WrapHandler(http.HandlerFunc(hello())))
	e.Run(standard.New(":1323"))
}
Ejemplo n.º 10
-1
func main() {
	e := echo.New()

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())
	e.Use(middleware.Static("public"))

	handler := Handler{"Hoł hoł"}
	e.GET("/ws", standard.WrapHandler(websocket.Handler(handler.WS)))

	e.Run(standard.New(":1323"))
}