### Quickstart: Initialize and Use etcd3 Client Source: https://github.com/microsoft/etcd3/blob/master/docs/globals.html Demonstrates how to install and initialize the etcd3 client, perform basic operations like PUT, GET, getAll with prefix, and DELETE. This example requires the 'etcd3' package to be installed. ```javascript const { Etcd3 } = require('etcd3'); const client = new Etcd3(); (async () => { await client.put('foo').value('bar'); const fooValue = await client.get('foo').string(); console.log('foo was:', fooValue); const allFValues = await client.getAll().prefix('f').keys(); console.log('all our keys starting with "f":', allFValues); await client.delete().all(); })(); ``` -------------------------------- ### Etcd3 Client Initialization Example (Node.js) Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/election.html Demonstrates how to initialize a new Etcd3 client instance using Node.js. This is a common starting point for interacting with etcd3 services. ```typescript const os = require('os'); const client = new Etcd3(); ``` -------------------------------- ### Install etcd3 Node.js Client Source: https://context7.com/microsoft/etcd3/llms.txt Installs the etcd3 Node.js client using npm. This is the first step to using the library in your project. ```bash npm install etcd3 ``` -------------------------------- ### Go: Basic Key-Value Operations in Etcd3 Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/icallcontext.html Demonstrates fundamental operations for putting and getting key-value pairs in etcd3 using the Go client library. It covers establishing a connection, performing put and get operations, and handling responses. No external dependencies beyond the etcd client library are required. ```go package main import ( "context" "fmt" "log" "time" "go.etcd.io/etcd/client/v3" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{"localhost:2379"}, DialTimeout: 5 * time.Second, }) if err != nil { log.Fatalf("unable to connect to etcd: %v", err) } defer cli.Close() ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) _, err = cli.Put(ctx, "sample_key", "sample_value") cancel() if err != nil { log.Fatalf("unable to put key-value: %v", err) } ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second) resp, err := cli.Get(ctx, "sample_key") cancel() if err != nil { log.Fatalf("unable to get key-value: %v", err) } for _, ev := range resp.Kvs { fmt.Printf("%s : %s\n", ev.Key, ev.Value) } } ``` -------------------------------- ### Start etcd3 Get Request Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/softwaretransaction.html Demonstrates initiating a key lookup in etcd using the `get` method of SoftwareTransaction. This method takes a key (string) as input and returns a SingleRangeBuilder for further query construction. It is defined in `src/stm.ts`. ```javascript tx.get(key: string): SingleRangeBuilder ``` -------------------------------- ### etcd3 Watcher Example (Go) Source: https://github.com/microsoft/etcd3/blob/master/docs/enums/queuestate.html Sets up a watcher to monitor changes for a specific key prefix in etcd. This is useful for reacting to dynamic configuration updates or distributed locks. Requires the etcd client library. ```go package main import ( "context" "log" "time" clientv3 "go.etcd.io/etcd/client/v3" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{"localhost:2379"}, }) if err != nil { log.Fatalf("Unable to connect to etcd: %v", err) } defer cli.Close() ctx, cancel := context.WithCancel(context.Background()) watchChan := cli.Watch(ctx, "mykey_prefix/") go func() { for watchResp := range watchChan { for _, ev := range watchResp.Events { log.Printf("%s %q : %q\n", ev.Type, ev.Kv.Key, ev.Kv.Value) } } }() // Simulate some puts to trigger the watcher cli.Put(ctx, "mykey_prefix/1", "value1") time.Sleep(2 * time.Second) cli.Put(ctx, "mykey_prefix/2", "value2") time.Sleep(2 * time.Second) cancel() // Stop the watcher log.Println("Watcher stopped.") } ``` -------------------------------- ### Etcd3 Client Initialization Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/etcd3.html Demonstrates how to initialize the Etcd3 client. ```APIDOC ## Etcd3 Client Initialization ### Description Initializes a new instance of the Etcd3 client. By default, it connects to `localhost:2379`. ### Method `constructor` ### Endpoint N/A ### Parameters None ### Request Example ```javascript const { Etcd3 } = require('etcd3'); const client = new Etcd3(); ``` ### Response #### Success Response (200) - **client** (object) - An instance of the Etcd3 client. #### Response Example ```json { "client": "[Etcd3 client object]" } ``` ``` -------------------------------- ### Get a Single Key within an Etcd3 Namespace Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/namespace.html Demonstrates how to start a query to retrieve a single key's value from etcd within a namespace. The `get()` method accepts a key as a string or Buffer and returns a `SingleRangeBuilder`. ```typescript get(key: string | Buffer): SingleRangeBuilder ``` -------------------------------- ### etcd3 Key-Value Operations (Get, Put, Delete) Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/grpcgenericerror.html Provides examples for performing basic key-value operations in etcd3, including getting a value, putting a new value, and deleting a key. These operations are essential for data management. ```typescript import { Client } from "@etcd3/client"; async function performKvOperations() { const client = new Client({ hosts: ["localhost:2379"] }); await client.connect(); // Put a key-value pair await client.put("mykey").value("myvalue").commit(); console.log("Put operation successful"); // Get a value const [value] = await client.get("mykey"); console.log(`Value for mykey: ${value.toString()}`); // Delete a key await client.delete("mykey").commit(); console.log("Delete operation successful"); await client.close(); } ``` -------------------------------- ### etcd3 Watcher Example Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/ialarmresponse.html Illustrates how to set up a watcher in etcd3 to monitor changes to specific keys or prefixes. This is crucial for building reactive distributed systems that respond to data modifications in real-time. ```go package main import ( "context" "log" "time" "go.etcd.io/etcd/client/v3" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{"localhost:2379"}, DialTimeout: 5 * time.Second, }) if err != nil { log.Fatalf("failed to connect to etcd: %v", err) } defer cli.Close() ctx, cancel := context.WithCancel(context.Background()) defer cancel() watchChan := cli.Watch(ctx, "mykey") for resp := range watchChan { for _, ev := range resp.Events { log.Printf("Event: %s, Key: %s, Value: %s\n", ev.Type, ev.Kv.Key, ev.Kv.Value) } } } ``` -------------------------------- ### Initialize etcd3 Client Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/etcd3.html Demonstrates how to create a new instance of the etcd3 client. This is the primary way to interact with the etcd cluster. No specific dependencies are required beyond the 'etcd3' package itself. ```javascript const { Etcd3 } = require('etcd3'); const client = new Etcd3(); ``` -------------------------------- ### Handle etcd Key-Value Operations in Node.js Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/ikeyvalue.html This Node.js code snippet demonstrates how to handle basic etcd key-value operations, including putting and getting data. It uses the 'etcd3' npm package. Ensure the 'etcd3' package is installed (`npm install etcd3`). ```javascript const etcd = require('etcd3'); async function main() { const client = new etcd.Etcd3({ hosts: 'http://localhost:2379', options: { 'requestTimeout': 1000 // 1 second } }); try { await client.put('mykey').value('myvalue').exec(); console.log('Successfully put key-value pair.'); const response = await client.get('mykey').exec(); if (response && response.kvs && response.kvs.length > 0) { console.log(`${response.kvs[0].key.toString()} : ${response.kvs[0].value.toString()}`); } else { console.log('Key not found.'); } } catch (err) { console.error('Error interacting with etcd:', err); } finally { await client.close(); } } main(); ``` -------------------------------- ### Get All Keys with Prefix in Etcd3 Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/etcd3.html Shows how to retrieve all keys that start with a specific prefix. This utilizes the client.getAll().prefix() method and then retrieves the values as strings using .strings(). ```typescript const keys = await client.getAll().prefix('f').strings(); console.log('all keys starting with "f"': keys); ``` -------------------------------- ### etcd3 Client Initialization and Basic Operations (Go) Source: https://github.com/microsoft/etcd3/blob/master/docs/enums/writekind.html Demonstrates how to initialize an etcd3 client and perform basic operations like putting and getting key-value pairs. This snippet is essential for interacting with an etcd cluster. ```Go package main import ( "context" "fmt" "log" "time" clientv3 "go.etcd.io/etcd/client/v3" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{"localhost:2379"}, DialTimeout: 5 * time.Second, }) if err != nil { log.Fatalf("unable to connect to etcd: %v", err) } defer cli.Close() ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) _, err = cli.Put(ctx, "mykey", "myvalue") cancel() if err != nil { log.Fatalf("unable to put key-value: %v", err) } ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second) resp, err := cli.Get(ctx, "mykey") cancel() if err != nil { log.Fatalf("unable to get key: %v", err) } for _, ev := range resp.Kvs { fmt.Printf("%s : %s\n", ev.Key, ev.Value) } } ``` -------------------------------- ### Etcd3 Client Initialization with gRPC Options Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/ioptions.html Demonstrates how to initialize the Etcd3 client and provide custom gRPC channel options. ```APIDOC ## Etcd3 Client Initialization with gRPC Options ### Description This section explains how to configure the Etcd3 client with optional gRPC channel options to customize the behavior of the underlying gRPC client. ### Method `new Etcd3(options)` ### Endpoint N/A (Client Initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **grpcOptions** (ChannelOptions) - Optional - Internal options to configure the GRPC client. These are channel options as enumerated in their [C++ documentation](https://grpc.io/grpc/cpp/group__grpc__arg__keys.html). ### Request Example ```javascript const etcd = new Etcd3({ hosts: 'localhost:2379', grpcOptions: { 'grpc.http2.max_ping_strikes': 3, 'grpc.keepalive_time_ms': 10000 } }); ``` ### Response #### Success Response (200) N/A (Client Initialization does not return a response in this context) #### Response Example N/A ``` -------------------------------- ### Query Lexer Token Emission (JavaScript) Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/iwatchrequest.html The `QueryLexer.prototype.emit` method records a recognized token. It calls `sliceString` to get the token's value, then pushes an object containing the token type, string value, start position, and end position into the `lexemes` array. It also resets the `start` position for the next token. ```javascript C.QueryLexer.prototype.emit = function(e) { this.lexemes.push({ type: e, str: this.sliceString(), start: this.start, end: this.pos }), this.start = this.pos; } ``` -------------------------------- ### etcd3 Client Initialization and Connection Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/iauthuserlistresponse.html Demonstrates how to initialize and establish a connection to an etcd3 cluster using different client libraries. This typically involves providing endpoint configurations and handling potential connection errors. ```go package main import ( "context" "log" "time" "go.etcd.io/etcd/client/v3" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{"localhost:2379"}, DialTimeout: 5 * time.Second, }) if err != nil { log.Fatalf("failed to connect to etcd: %v", err) } defer cli.Close() ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) _, err = cli.Get(ctx, "sample_key") cancel() if err != nil { log.Printf("failed to get key: %v", err) } else { log.Println("Successfully connected to etcd") } } ``` -------------------------------- ### Go etcd Client Operations Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/iauthroledeleteresponse.html Demonstrates common operations for interacting with an etcd cluster using the Go client library. This includes putting key-value pairs, getting values, and handling potential errors. It assumes the etcd client library is installed. ```go package main import ( "context" "fmt" "log" "time" "go.etcd.io/etcd/client/v3" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{"localhost:2379"}, DialTimeout: 5 * time.Second, }) if err != nil { log.Fatalf("unable to connect to etcd: %v", err) } defer cli.Close() ctx, cancel := context.WithTimeout(context.Background(), time.Second) _, err = cli.Put(ctx, "myKey", "myValue") cancel() if err != nil { log.Fatalf("unable to put key-value: %v", err) } fmt.Println("Successfully put key-value pair.") ctx, cancel = context.WithTimeout(context.Background(), time.Second) resp, err := cli.Get(ctx, "myKey") cancel() if err != nil { log.Fatalf("unable to get key: %v", err) } if len(resp.Kvs) == 0 { fmt.Println("Key not found.") } else { fmt.Printf("Got value for myKey: %s\n", resp.Kvs[0].Value) } } ``` -------------------------------- ### lunr.js Initialization and Configuration Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/etcdauthenticationfailederror.html Demonstrates how to initialize and configure the lunr.js library, including adding pipeline functions and building the search index. It utilizes a builder pattern for customization. ```javascript var lunr = require('lunr'); var builder = new lunr.Builder(); builder.pipeline.add(lunr.trimmer, lunr.stopWordFilter, lunr.stemmer); builder.searchPipeline.add(lunr.stemmer); var index = builder.build(); ``` -------------------------------- ### Run etcd3 Tests Source: https://github.com/microsoft/etcd3/blob/master/readme.md Provides instructions for setting up and running tests for the etcd3 client. This involves installing dependencies, starting a local etcd3 server using Docker Compose, running the tests, and then shutting down the server. ```bash $ npm install $ cd src/test/containers/3.2 && docker-compose up # in a separate shell $ npm test $ docker-compose down ``` -------------------------------- ### Handle etcd Key-Value Operations in Go Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/ikeyvalue.html This Go code snippet demonstrates how to handle basic etcd key-value operations, including putting and getting data. It utilizes the etcd client library for Go. Ensure the etcd client library is installed and accessible. ```go package main import ( "context" "fmt" "log" "time" "go.etcd.io/etcd/client/v3" ) func main() { cli, err := clientv3.New(clientv3.Config{ Endpoints: []string{"localhost:2379"}, DialTimeout: 5 * time.Second, }) if err != nil { log.Fatalf("unable to connect to etcd: %v", err) } defer cli.Close() ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) _, err = cli.Put(ctx, "mykey", "myvalue") cancel() if err != nil { log.Fatalf("unable to put key-value: %v", err) } ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second) resp, err := cli.Get(ctx, "mykey") cancel() if err != nil { log.Fatalf("unable to get key-value: %v", err) } for _, ev := range resp.Kvs { fmt.Printf("%s : %s\n", ev.Key, ev.Value) } } ``` -------------------------------- ### Lunr Library Initialization and Configuration (JavaScript) Source: https://github.com/microsoft/etcd3/blob/master/docs/enums/sorttarget.html This snippet demonstrates the initialization and configuration of the lunr library, a search engine. It includes setting up a builder, adding pipeline functions like trimming, stop word filtering, and stemming, and building the search index. It also defines utility functions and core components of the lunr library. ```javascript !function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=2)}([function(e,t,r){var n,i; /*! * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.9 * Copyright (C) 2020 Oliver Nightingale * @license MIT */!function(){var s,o,a,u,l,c,h,d,f,p,y,m,v,g,x,w,L,E,b,S,k,Q,O,P,T,_=function(e){var t=new _.Builder;return t.pipeline.add(_.trimmer,_.stopWordFilter,_.stemmer),t.searchPipeline.add(_.stemmer),e.call(t,t),t.build()},C=function(e){if(this.elements=Object.create(null),e){this.length=e.length;for(var t=0;t0){var u=_.utils.clone(t)||{};u.position=[o,a],u.index=i.length,i.push(new _.Token(r.slice(o,s),u))}o=s+1}}return i},_.tokenizer.separator=/[s\-]+/ /*! * lunr.Pipeline * Copyright (C) 2020 Oliver Nightingale */,D.registeredFunctions=Object.create(null),D.registerFunction=function(e,t){t in this.registeredFunctions&&_.utils.warn("Overwriting existing registered function: "+t),e.label=t,D.registeredFunctions[e.label]=e},D.warnIfFunctionNotRegistered=function(e){e.label&&e.label in D.registeredFunctions||_.utils.warn("Function is not reg" ``` -------------------------------- ### Execute Atomic Transaction with etcd3 Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/softwaretransaction.html Demonstrates how to perform an atomic transaction using etcd3's SoftwareTransaction. This example simulates a bank transfer by getting two account balances, checking for sufficient funds, and then updating the balances. It utilizes `Promise.all` for concurrent operations and throws an error if the balance is insufficient. Dependencies include the etcd3 library. ```javascript etcd3.stm().transact(tx => { return Promise.all([ tx.get('bank/account1').number(), tx.get('bank/account2').number(), ]).then(([balance1, balance2]) => { if (balance1 < amount) { throw new Error('You do not have enough money to transfer!'); } return Promise.all([ tx.put('bank/account1').value(balance1 - amount), tx.put('bank/account2').value(balance2 + amount), ]); }); }); ``` -------------------------------- ### Application Initialization Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/icompactionresponse.html Initializes the main application object and exposes it globally as `window.app`. This is typically the entry point for the application's logic. ```javascript var N = new a; Object.defineProperty(window, "app", { value: N }) ``` -------------------------------- ### Get Role Information (TypeScript) Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/authclient.html Retrieves detailed information about a specific role. This function takes a role get request object and optional gRPC call options, returning a promise that resolves to the role get response. ```typescript roleGet(req: IAuthRoleGetRequest, options?: grpc.CallOptions): Promise ``` -------------------------------- ### Create an etcd client in Go Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/etcdlockfailederror.html This Go code snippet shows how to initialize and configure an etcd client. It specifies endpoints, timeouts, and authentication mechanisms required to connect to an etcd cluster. Proper client configuration is essential for reliable etcd operations. ```go func NewEtcdClient(endpoints []string, username, password string, dialTimeout time.Duration) (*EtcdClient, error) { cli, err := clientv3.New(clientv3.Config{ Endpoints: endpoints, Username: username, Password: password, DialTimeout: dialTimeout, }) if err != nil { return nil, fmt.Errorf("failed to create etcd client: %w", err) } return &EtcdClient{client: cli}, } ``` -------------------------------- ### Application Initialization and Event Handling Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/iauthroledeleterequest.html Initializes the application by setting up search, menu highlighting, signature display, and toggleable elements. It also handles various DOM events for user interaction. Dependencies include DOM manipulation and event listeners. ```javascript r(1);i(h,"#tsd-search"),i(v,".menu-highlight"),i(w,".tsd-signatures"),i(\_,"a[data-toggle]"),F.isSupported()?i(F,"#tsd-filter"):document.documentElement.classList.add("no-filter");var N=new a;Object.defineProperty(window,"app",{value:N})} ``` -------------------------------- ### lunr.js Initialization and Pipeline Configuration Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/clientruntimeerror.html Demonstrates how to initialize lunr.js with a builder and configure its processing pipeline. This includes adding functions like trimming, stop word filtering, and stemming. It also shows how to build the search index. ```javascript var builder = new lunr.Builder(); builder.pipeline.add(lunr.trimmer, lunr.stopWordFilter, lunr.stemmer); builder.searchPipeline.add(lunr.stemmer); var index = builder.build(); ``` -------------------------------- ### Start an Etcd3 Transaction with Conditional Logic Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/namespace.html Explains how to start an etcd transaction with conditional logic using the `if()` method. This allows for atomic execution of statements based on key comparisons. ```typescript if(key: string | Buffer, column: keyof typeof compareTarget, cmp: keyof typeof comparator, value: string | Buffer | number): ComparatorBuilder ``` -------------------------------- ### lunr.js Initialization and Configuration Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/iauthuserrevokerolerequest.html This snippet demonstrates how to initialize and configure the lunr.js library. It shows the creation of a builder, adding pipeline functions, and building the search index. This is useful for setting up a search functionality within an application. ```javascript var builder = new lunr.Builder(); builder.pipeline.add(lunr.trimmer, lunr.stopWordFilter, lunr.stemmer); builder.searchPipeline.add(lunr.stemmer); var lunrIndex = builder.build(); ``` -------------------------------- ### GET /role/permissions Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/role.html Returns a list of permissions the role has. ```APIDOC ## GET /role/permissions ### Description Returns a list of permissions the role has. ### Method GET ### Endpoint /role/permissions ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```json { "options": {} } ``` ### Response #### Success Response (200) - **permissions** (IPermissionResult[]) - A list of permission objects. #### Response Example ```json [ { "key": "/path/to/resource", "rangeEnd": "/path/to/resource/end", "permission": "read" } ] ``` ``` -------------------------------- ### Key-Value Operations: Put and Get Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/iauthuseraddresponse.html Illustrates how to perform basic key-value operations in etcd, specifically putting (setting) a value for a key and getting (retrieving) the value associated with a key. Handles potential errors during these operations. ```typescript import { Etcd3 } from 'etcd3'; const client = new Etcd3({ hosts: 'localhost:2379' }); async function putAndGetKeys() { const key = '/mykey'; const value = 'myvalue'; try { // Put a key-value pair await client.put(key).value(value); console.log(`Successfully put key: ${key} with value: ${value}`); // Get the value for the key const result = await client.get(key); if (result) { console.log(`Successfully got key: ${key} with value: ${result.value}`); } else { console.log(`Key ${key} not found.`); } } catch (error) { console.error('Error performing key-value operations:', error); } } putAndGetKeys(); ``` -------------------------------- ### RANGE API Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/kvclient.html Gets the keys in the range from the key-value store. ```APIDOC ## RANGE /kv/range ### Description Gets the keys in the range from the key-value store. ### Method GET ### Endpoint /kv/range ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **req** (object) - Required - The request object conforming to IRangeRequest. - **options** (object) - Optional - gRPC call options. ### Request Example ```json { "req": { ... IRangeRequest details ... }, "options": { ... grpc.CallOptions details ... } } ``` ### Response #### Success Response (200) - **response** (object) - The response object conforming to IRangeResponse. #### Response Example ```json { "response": { ... IRangeResponse details ... } } ``` ``` -------------------------------- ### lunr Library Initialization and Configuration Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/iauthuserchangepasswordresponse.html This snippet demonstrates the initialization and configuration of the lunr search library. It includes setting up a builder, adding pipeline functions like trimming, stop word filtering, and stemming, and building the search index. The code is self-contained and does not require external dependencies beyond the lunr library itself. ```javascript !function(){var s,o,a,u,l,c,h,d,f,p,y,m,v,g,x,w,L,E,b,S,k,Q,O,P,T,_=function(e){var t=new C.Builder;return t.pipeline.add(C.trimmer,C.stopWordFilter,C.stemmer),t.searchPipeline.add(C.stemmer),e.call(t,t),t.build()};C.version="2.3.9" /*! * lunr.utils * Copyright (C) 2020 Oliver Nightingale */,C.utils={},C.utils.warn=(s=this,function(e){s.console&&console.warn&&console.warn(e)}),C.utils.asString=function(e){return null==e?"":e.toString()},C.utils.clone=function(e){if(null==e)return e;for(var t=Object.create(null),r=Object.keys(e),n=0;n0){var u=C.utils.clone(t)||{};u.position=[o,a],u.index=i.length,i.push(new C.Token(r.slice(o,s),u))}o=s+1}}return i},C.tokenizer.separator=/[\s\-]+/ /*! * lunr.Pipeline * Copyright (C) 2020 Oliver Nightingale */,C.Pipeline=function(){this._stack=[]},C.Pipeline.registeredFunctions=Object.create(null),C.Pipeline.registerFunction=function(e,t){t in this.registeredFunctions&&C.utils.warn("Overwriting existing registered function: "+t),e.label=t,C.Pipeline.registeredFunctions[e.label]=e},C.Pipeline.warnIfFunctionNotRegistered=function(e){e.label&&e.label in this.registeredFunctions} ``` -------------------------------- ### removeProtocolPrefix Source: https://github.com/microsoft/etcd3/blob/master/docs/globals.html Strips the https?:// from the start of the connection string. ```APIDOC ## removeProtocolPrefix ### Description Strips the https?:// from the start of the connection string. ### Method (Not specified, likely a utility function) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "name": "https://example.com" } ``` ### Response #### Success Response (200) - **string**: The connection string without the protocol prefix. #### Response Example ```json { "example": "example.com" } ``` ``` -------------------------------- ### lunr.js Initialization and Configuration Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/icomparetarget.html Demonstrates how to initialize and configure the lunr.js library, including adding pipeline functions for text processing. This is typically used for search indexing. ```javascript var lunr = function(e) { var t = new lunr.Builder; t.pipeline.add(lunr.trimmer, lunr.stopWordFilter, lunr.stemmer); t.searchPipeline.add(lunr.stemmer); e.call(t, t); return t.build(); }; lunr.version = "2.3.9"; ``` -------------------------------- ### Go: Etcd Watcher for Key Changes Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/basictransaction.html Illustrates how to set up a watcher in Go to monitor changes for a specific key in etcd. This is useful for reacting to updates in real-time. It depends on the etcd client library. ```go package main import ( "context" "fmt" "log" "time" "go.etcd.io/etcd/client/v3" ) func main() { cli, err := client.New(client.Config{ Endpoints: []string{"localhost:2379"}, DialTimeout: 5 * time.Second, }) if err != nil { log.Fatalf("failed to connect to etcd: %v", err) } defer cli.Close() ctx, cancel := context.WithCancel(context.Background()) watchChan := cli.Watch(ctx, "mykey") go func() { for resp := range watchChan { for _, ev := range resp.Events { fmt.Printf("Type: %s, Key: %s, Value: %s\n", ev.Type, ev.Kv.Key, ev.Kv.Value) } } }() // Keep the main goroutine alive to observe watch events select {} } ``` -------------------------------- ### Get etcd key-value pair in Go Source: https://github.com/microsoft/etcd3/blob/master/docs/classes/etcdlockfailederror.html This Go code snippet demonstrates how to retrieve a key-value pair from etcd. It uses the etcd client to perform a GET operation and handles potential errors, such as the key not being found. This is a fundamental operation for reading data from etcd. ```go func (c *EtcdClient) Get(ctx context.Context, key string) (string, error) { resp, err := c.client.Get(ctx, key) if err != nil { return "", fmt.Errorf("failed to get key '%s': %w", key, err) } if len(resp.Kvs) == 0 { return "", fmt.Errorf("key '%s' not found", key) } return string(resp.Kvs[0].Value), } ``` -------------------------------- ### IAuthUserGetRequest Source: https://github.com/microsoft/etcd3/blob/master/docs/interfaces/iauthusergetrequest.html Defines the structure for a request to get authentication user information. ```APIDOC ## IAuthUserGetRequest ### Description Represents the parameters required for an authentication user get request. ### Method GET (Implied by request structure) ### Endpoint Not specified, typically part of a larger authentication endpoint. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (string) - Required - The name of the user to authenticate or retrieve. ### Request Example ```json { "name": "example_user" } ``` ### Response #### Success Response (200) - **(Structure not defined in provided text)** - Description of the user information returned. #### Response Example ```json { "example": "response body" } ``` ```