Lenses Client (Go)
The Lenses REST API client written in Go.
![chat](https://img.shields.io/badge/join-%20chat-00BCD4.svg?style=flat-square)
Installation
The only requirement is the Go Programming Language version 1.19+ and a Lenses Box of version 5.1 at least.
$ go install github.com/lensesio/lenses-go/v5/cmd/lenses-cli@latest
This command will install both the client library for development usage and the CLI in $PATH (setup your $GOPATH/bin if you didn't already).
CLI
Lenses offers a powerful CLI (command-line tool) built in Go that utilizes the REST and WebSocket APIs of Lenses, to communicate with Apache Kafka and exposes a straight forward way to perform common data engineering and site reliability engineering tasks, such as:
- Automate your CI/CD (continuous-integration and continuous-delivery)
- Create topics/acls/quotas/schemas/connectors/processors
- Change or retrieve configurations to store in github
Documentation
Please navigate to https://docs.lenses.io/dev/lenses-cli/ to learn how to install and use the lenses-cli
.
Development
Build
lenses-go
use go modules as dependency management system. For daily development workflow you need to use Makefile
with certain actions.
Builds a binary based on your current OS system
make build
Builds binaries for all OS systems
make cross-build
Lint
We use the Golang golint for linting using:
make lint
Tests
If you want to run the tests, use the following:
make test
Clean
Clean all binaries and coverage files:
make clean
Client
Getting started
import "github.com/lensesio/lenses-go/v5"
Authentication
auth := lenses.BasicAuthentication{Username: "user", Password: "pass"}
auth := lenses.KerberosAuthentication{
ConfFile: "/etc/krb5.conf",
Method: lenses.KerberosWithPassword{
Realm: "my.realm or default if empty",
Username: "user",
Password: "pass",
},
}
auth := lenses.KerberosAuthentication{
ConfFile: "/etc/krb5.conf",
Method: lenses.KerberosWithKeytab{KeytabFile: "/home/me/krb5_my_keytab.txt"},
}
auth := lenses.KerberosAuthentication{
ConfFile: "/etc/krb5.conf",
Method: lenses.KerberosFromCCache{CCacheFile: "/tmp/krb5_my_cache_file.conf"},
}
Custom auth can be implement as well: Authenticate(client *lenses.Client) error
, see client_authentication.go file for more.
Config
currentConfig := lenses.ClientConfig{Host: "domain.com", Authentication: auth, Timeout: "15s", Debug: true}
client, err := lenses.OpenConnection(currentConfig)
if err != nil {
}
Read Config
from any io.Reader
or file
ReadConfig(r io.Reader, unmarshaler UnmarshalFunc, outPtr *Config) error
ReadConfigFromFile(filename string, unmarshaler UnmarshalFunc, outPtr *Config) error
TryReadConfigFromFile(filename string, outPtr *Config) error
TryReadConfigFromHome(outPtr *Config) bool
TryReadConfigFromExecutable(outPtr *Config) bool
TryReadConfigFromCurrentWorkingDir(outPtr *Config) bool
ReadConfigFromJSON(filename string, outPtr *Config) error
ReadConfigFromYAML(filename string, outPtr *Config) error
Example Code:
CurrentContext: main
Contexts:
main:
Host: https://<your-lenses-host-url>
Kerberos:
ConfFile: /etc/krb5.conf
WithPassword:
Username: the_username
Password: the_password
Realm: empty_for_default
Usage:
var config lenses.Config
err := lenses.ReadConfigFromYAML("./lenses.yml", &config)
if err != nil {
}
client, err := lenses.OpenConnection(*config.GetCurrent())
Config
contains tons of capabilities and helpers, you can quickly check them by navigating to the config.go source file.
API Calls
All lenses-go#Client
methods return a typed value based on the call
and an error as second output to catch any errors coming from backend or client, forget panics.
Go types are first class citizens here, we will not confuse you or let you work based on luck!
topics, err := client.GetTopics()
if err != nil {
}
print(len(topics))
Example on how deeply we make the difference here:
Client#GetTopics
returns []lenses.Topic
, so you can work safely.
topics[0].ConsumersGroup[0].Coordinator.Host
Documentation
Detailed documentation can be found at godocs.
Versioning
License
Distributed under Apache Version 2.0 License, click here for more details.