Etcd


etcd-io/etcd를 사용하는 Etcd 스토리지 드라이버입니다.

참고: Go 1.19 이상이 필요합니다

Table of Contents

  • Signatures

  • Installation

  • Examples

  • Config

  • Default Config

Signatures

func New(config ...Config) *Storage

func (s *Storage) Get(key string) ([]byte, error)

func (s *Storage) Set(key string, val []byte, exp time.Duration) error

func (s *Storage) Delete(key string) error

func (s *Storage) Reset() error

func (s *Storage) Close() error

func (s *Storage) Conn() clientv3.Client

Installation

Etcd는 모듈 지원을 통해 Go versions의 최신 2개 버전에서 테스트됩니다. 아직 모듈을 초기화하지 않았다면 먼저 초기화하세요:

go mod init github.com/<user>/<repo>

그런 다음 etcd 구현을 설치하세요:

go get github.com/gofiber/storage/etcd/v2

Examples

스토리지 패키지를 임포트하세요.

import "github.com/gofiber/storage/etcd/v2"

다음과 같은 방법으로 스토리지를 생성할 수 있습니다:

// 기본 설정으로 초기화
store := etcd.New()

// 사용자 정의 설정으로 초기화
store := etcd.New(Config{
  Endpoints: []string{"localhost:2379"},
})

Config

type Config struct {
    // Endpoints는 URL 목록입니다.
    Endpoints []string

    // DialTimeout은 연결 설정 실패 시 타임아웃입니다.
    DialTimeout time.Duration

    // Username은 인증을 위한 사용자 이름입니다.
    Username string

    // Password는 인증을 위한 비밀번호입니다.
    Password string

    // TLS는 클라이언트 보안 자격 증명을 보유합니다(있는 경우).
    TLS *tls.Config
}

Default Config

var ConfigDefault = Config{
    Endpoints:   []string{"localhost:2379"},
    DialTimeout: 2 * time.Second,
    Username:    "",
    Password:    "",
    TLS:         nil,
}

Last updated