Get started

Get started

To learn more about Lekko’s philosophy and core features, take a look at our Introduction!

This guide will get you started on creating a Lekko account, connecting a code repository, and using lekkos (dynamic functions) in your code.

Prerequisites

You can also create an example project from one of our templates:

You can use our Go template project published here: https://github.com/lekkodev/go-template (opens in a new tab)

On GitHub, you can select "Use this template" → "Create a new repository" to create a repository based on this template in your personal or team organization.

Use this template screenshot

Steps

Create a Lekko account

Go to the web UI (opens in a new tab) and sign up for an account. Lekko walks you through additional steps like setting up your organization with GitHub integration. Once you have an account, you can proceed with the next steps.

Initialize Lekko in your code repository

Run the following commands in your terminal to install the Lekko CLI:

brew tap lekkodev/lekko && brew install lekko

Run lekko init in the root of your project to initialize Lekko.

lekko init

This will:

  • Create a .lekko file with basic configuration
  • Add GitHub workflow to mirror lekko changes to Lekko
  • Automatically install dependency libraries suitable for your project

Add Lekko build decorators

Lekko works by decorating (wrapping) your simple functions to make them lekkos during your build. At runtime, these decorated functions will fetch their latest value from Lekko when the LEKKO_API_KEY environment variable is set.

Because Go does not expose any build steps, your best bet is to insert the lekko bisync command (which performs code checking & generation) into a codegen step into build tools like Makefiles.

For more information check out the Go SDK reference.

Use a new lekko in your code

Your project should have had a Lekko directory created with an example file (e.g. in src/lekko). Functions in files under this directory are lekkos and can be dynamically connected to Lekko’s services.

ℹ️

This directory is specified by the lekko_path field in the .lekko file that was generated when you ran lekko init. To choose a different directory, you just need to modify this field.

Try adding and changing lekkos here, following our SDK docs for your language/framework or the examples below.

Here are some ideas for basic lekkos for inspiration:

  • A feature flag for conditionally rendering a component
  • Text content for your landing page depending on the visitor's region
  • Log level controller for your service based on the error message or HTTP code

Add a lekko:

internal/lekko/example/example.go
package lekkoexample
 
// Return text based on environment
func getReturnText(env string) string {
    if env == "production" {
        return "foobar"
    } else if env == "development" {
        return "foo"
    }
    return "bar"
}

Run bisync in your terminal at the project root to trigger code generation:

lekko bisync

Use the lekko in your code!

main.go
package main
 
import (
    "context"
    "log"
    "net/http"
    "os"
 
    "example/lekko"
)
 
func main() {
    env := os.Getenv("ENV")
    client := lekko.NewLekkoClient(context.TODO())
    // Start a simple HTTP server on localhost:8080
    // You can send requests using `curl localhost:8080`
    addr := ":8080"
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte(client.Example.GetReturnText(env)))
    })
    log.Println("Listening on", addr)
    log.Fatal(http.ListenAndServe(addr, nil))
}

Generate a Lekko API key

For the next steps which involve connecting to Lekko's services, you need to generate an API key.

You can generate API keys on the web UI here (opens in a new tab).

Add Lekko API key to GitHub secret

For the Lekko GitHub Action to work correctly, you need to set LEKKO_API_KEY as a repository secret (opens in a new tab) on GitHub.

You can do this by going to your code repository on GitHub → Settings → Secrets and variables → Actions.

Repository secret

Open a pull request with your changes

With the lekko changes from the previous step, try opening a new pull request.

After all checks are completed, you should see a message like this:

Lekko Connected Success Lekko Push Action example

Update a lekko remotely

Now to make lekkos dynamic at runtime, just set the LEKKO_API_KEY environment variable when building/running your project.

LEKKO_API_KEY=<API key> go run main.go

And make a change in the UI using our web UI at app.lekko.com (opens in a new tab). Here, you can track the history of your lekkos, manage team members, view the estimated impact of your changes, and more.

You should see the lekkos you set up in the earlier steps on your dashboard. Try making some changes and see how they affect your live project, without any redeployments!

💡

During development, you want to avoid having remote dependencies and test your local code/lekko changes without other people's changes affecting you. Achieving this is as simple as not setting LEKKO_API_KEY in your dev environment!

What’s next

You have successfully set up Lekko! 🎉

After following this guide, you should have:

  • A Lekko account
  • A Lekko team tied to your GitHub organization
  • Your project, with Lekko workflows/dependencies installed
  • A Lekko API key for deploying with your project

And you should now have all the skills to use Lekko in production.

Feel free to continue exploring language- and framework-specific SDKs for more in-depth explanations on connecting your existing projects with Lekko and setting up related tools.