Skip to content

ecclibase/oksana

Repository files navigation

Build Status codecov GoDoc Go Report Card

Oksana

Microservice framework written in Go.

Meaning

Slavic meaning of Oksana "praise to God"

Example

func main() {
    o := oksana.New()

    // index handler
    o.GET("/", func(c oksana.Context) error {
        return c.JSON(200, "Hello World!")
    })

    o.Start()
}

Config

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.

Routes

Add Routes

// 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)

Route Groups

// Create Route Group
g := o.Group('/prefix')
g.GET('/endpoint', handler)  // GET /prefix/endpoint
g.POST('/endpoint', handler) // POST /prefix/endpoint

Middleware

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)

Development

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.

Releases

No releases published

Packages

No packages published