示例#1
0
文件: server.go 项目: AlekSi/echo
func main() {
	e := echo.New()
	e.GET("/request", request)
	e.GET("/stream", stream)
	e.Run(standard.WithConfig(engine.Config{
		Address:     ":1323",
		TLSCertFile: "cert.pem",
		TLSKeyFile:  "key.pem",
	}))
}
示例#2
0
文件: server.go 项目: medigo/laika
// 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
}