Microservice framework written in Go.
Slavic meaning of Oksana "praise to God"
func main() {
o := oksana.New()
// index handler
o.GET("/", func(c oksana.Context) error {
return c.JSON(200, "Hello World!")
})
o.Start()
}
Oksana provides the ability to configure your service from a central config file.
Copy .env.example
to .env
into the source of your service. You can place any
environment variables into this file. The .env
is loaded into a Config struct
which can be read from anywhere in the service.
// Add GET route
o.GET('/endpoint', handler)
// Add DELETE route
o.DELETE('/endpoint', handler)
// Add PATCH route
o.PATCH('/endpoint', handler)
// Add POST route
o.POST('/endpoint', handler)
// Add PUT route
o.PUT('/endpoint', handler)
// Create Route Group
g := o.Group('/prefix')
g.GET('/endpoint', handler) // GET /prefix/endpoint
g.POST('/endpoint', handler) // POST /prefix/endpoint
Groups can have defined middleware. These middleware handlers will be executed for every route within the group:
g := o.Group('/prefix', middlewareHandler1, middlewareHandler1)
Groups can have middleware handlers that are executed for every route within the group:
g := o.Group('/prefix')
g.Middleware(middlwareHandler1)
g.Middleware(middlwareHandler2)
If you need middleware to be executed on specific routes you can add middleware to the route definition:
g := o.Group('/prefix')
g.GET('/endpoint', handler, middleware)
Oksana uses golang's dep for dependency management. Make sure dep is installed on your local development machine.
To pull in the required dependencies, run the following command: dep ensure
.