Exemple #1
0
func main() {
	e := vodka.New()

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

	// Login route
	e.POST("/login", login)

	// Unauthenticated route
	e.GET("/", accessible)

	// Restricted group
	r := e.Group("/restricted")

	// Configure middleware with the custom claims type
	config := middleware.JWTConfig{
		Claims:     &jwtCustomClaims{},
		SigningKey: []byte("secret"),
	}
	r.Use(middleware.JWTWithConfig(config))
	r.GET("", restricted)

	e.Run(standard.New(":1323"))
}
Exemple #2
0
func main() {
	e := vodka.New()

	// Debug mode
	e.SetDebug(true)

	//-------------------
	// Custom middleware
	//-------------------
	// Stats
	s := NewStats()
	e.Use(s.Process)
	e.GET("/stats", s.Handle) // Endpoint to get stats

	// Server header
	e.Use(ServerHeader)

	// Handler
	e.GET("/", func(c vodka.Context) error {
		return c.String(http.StatusOK, "Hello, World!")
	})

	// Start server
	e.Run(standard.New(":1323"))
}
Exemple #3
0
func main() {
	e := vodka.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"))
}
Exemple #4
0
func main() {
	// the appengine package provides a convenient method to handle the health-check requests
	// and also run the app on the correct port. We just need to add Vodka to the default handler
	s := standard.New(":8080")
	s.SetHandler(e)
	http.Handle("/", s)
	appengine.Main()
}
Exemple #5
0
func main() {
	e := vodka.New()
	e.GET("/", func(c vodka.Context) error {
		return c.String(http.StatusOK, "Six sick bricks tick")
	})
	std := standard.New(":1323")
	std.SetHandler(e)
	gracehttp.Serve(std.Server)
}
Exemple #6
0
func main() {
	// Setup
	e := vodka.New()
	e.GET("/", func(c vodka.Context) error {
		return c.String(http.StatusOK, "Sue sews rose on slow joe crows nose")
	})
	std := standard.New(":1323")
	std.SetHandler(e)
	graceful.ListenAndServe(std.Server, 5*time.Second)
}
Exemple #7
0
func main() {
	e := vodka.New()

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

	e.POST("/upload", upload)

	e.Run(standard.New(":1323"))
}
Exemple #8
0
func createMux() *vodka.Vodka {
	e := vodka.New()

	// note: we don't need to provide the middleware or static handlers, that's taken care of by the platform
	// app engine has it's own "main" wrapper - we just need to hook vodka into the default handler
	s := standard.New("")
	s.SetHandler(e)
	http.Handle("/", s)

	return e
}
Exemple #9
0
func main() {
	e := vodka.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"))
}
Exemple #10
0
func main() {
	e := vodka.New()

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

	// Routes
	e.POST("/users", createUser)
	e.GET("/users/:id", getUser)
	e.PUT("/users/:id", updateUser)
	e.DELETE("/users/:id", deleteUser)

	// Start server
	e.Run(standard.New(":1323"))
}
Exemple #11
0
func main() {
	e := vodka.New()
	e.GET("/", func(c vodka.Context) error {
		c.Response().Header().Set(vodka.HeaderContentType, vodka.MIMEApplicationJSON)
		c.Response().WriteHeader(http.StatusOK)
		for _, l := range locations {
			if err := json.NewEncoder(c.Response()).Encode(l); err != nil {
				return err
			}
			c.Response().(http.Flusher).Flush()
			time.Sleep(1 * time.Second)
		}
		return nil
	})
	e.Run(standard.New(":1323"))
}
Exemple #12
0
func main() {
	// Vodka instance
	e := vodka.New()

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

	// Route => handler
	e.GET("/", func(c vodka.Context) error {
		return c.String(http.StatusOK, "Hello, World!\n")
	})

	// Start server
	e.Run(standard.New(":1323"))
}
Exemple #13
0
func main() {
	e := vodka.New()

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

	// Login route
	e.POST("/login", login)

	// Unauthenticated route
	e.GET("/", accessible)

	// Restricted group
	r := e.Group("/restricted")
	r.Use(middleware.JWT([]byte("secret")))
	r.GET("", restricted)

	e.Run(standard.New(":1323"))
}
Exemple #14
0
func main() {
	e := vodka.New()
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	// CORS default
	// Allows requests from any origin wth GET, HEAD, PUT, POST or DELETE method.
	// e.Use(middleware.CORS())

	// CORS restricted
	// Allows requests from any `https://insionng.com` or `https://insionng.net` origin
	// wth GET, PUT, POST or DELETE method.
	e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
		AllowOrigins: []string{"https://insionng.com", "https://insionng.net"},
		AllowMethods: []string{vodka.GET, vodka.PUT, vodka.POST, vodka.DELETE},
	}))

	e.GET("/api/users", getUsers)
	e.Run(standard.New(":1323"))
}
Exemple #15
0
func main() {
	e := vodka.New()
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())
	e.Use(middleware.Static("public"))

	// JSONP
	e.GET("/jsonp", func(c vodka.Context) error {
		callback := c.QueryParam("callback")
		var content struct {
			Response  string    `json:"response"`
			Timestamp time.Time `json:"timestamp"`
			Random    int       `json:"random"`
		}
		content.Response = "Sent via JSONP"
		content.Timestamp = time.Now().UTC()
		content.Random = rand.Intn(1000)
		return c.JSONP(http.StatusOK, callback, &content)
	})

	// Start server
	e.Run(standard.New(":1323"))
}
Exemple #16
0
func main() {
	// Hosts
	hosts := make(map[string]*Host)

	//-----
	// API
	//-----

	api := vodka.New()
	api.Use(middleware.Logger())
	api.Use(middleware.Recover())

	hosts["api.localhost:1323"] = &Host{api}

	api.GET("/", func(c vodka.Context) error {
		return c.String(http.StatusOK, "API")
	})

	//------
	// Blog
	//------

	blog := vodka.New()
	blog.Use(middleware.Logger())
	blog.Use(middleware.Recover())

	hosts["blog.localhost:1323"] = &Host{blog}

	blog.GET("/", func(c vodka.Context) error {
		return c.String(http.StatusOK, "Blog")
	})

	//---------
	// Website
	//---------

	site := vodka.New()
	site.Use(middleware.Logger())
	site.Use(middleware.Recover())

	hosts["localhost:1323"] = &Host{site}

	site.GET("/", func(c vodka.Context) error {
		return c.String(http.StatusOK, "Website")
	})

	// Server
	e := vodka.New()
	e.Any("/*", func(c vodka.Context) (err error) {
		req := c.Request()
		res := c.Response()
		host := hosts[req.Host()]

		if host == nil {
			err = vodka.ErrNotFound
		} else {
			host.Vodka.ServeHTTP(req, res)
		}

		return
	})
	e.Run(standard.New(":1323"))
}
Exemple #17
0
func main() {
	e.Run(standard.New(":8080"))
}