etcdfs

package module
v0.0.0-...-d24a1ed Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2018 License: BSD-3-Clause Imports: 10 Imported by: 0

README

etcdfs: virtual file system on etcd

Build Status Go Report Card GoDoc

Install

  1. go get github.com/chai2010/etcdfs

Example

Start etcd in local:

etcd

Put some data to edcd:

ETCDCTL_API=3 etcdctl put /abc/readme.md abc/aaa-value
ETCDCTL_API=3 etcdctl put /abc/hello.go  "package main; func main(){}"
ETCDCTL_API=3 etcdctl get --prefix ""

Create go progrom:

package main

import (
	"flag"
	"log"
	"net/http"
	"strings"
	"time"

	"golang.org/x/tools/godoc/vfs"
	"golang.org/x/tools/godoc/vfs/httpfs"

	"github.com/chai2010/etcdfs"
)

var (
	flagEtcdHost = flag.String("ectd-host", "localhost:2379", "set etcd nodes")
)

func main() {
	flag.Parse()

	etcdClient, err := etcdfs.NewEtcdClient(strings.Split(*flagEtcdHost, ","), time.Second/10)
	if err != nil {
		log.Fatal(err)
	}

	ns := vfs.NameSpace{}
	ns.Bind("/", etcdfs.New(etcdClient), "/", vfs.BindReplace)

	http.Handle("/", http.FileServer(httpfs.New(ns)))

	log.Fatal(http.ListenAndServe(":8080", nil))
}

Run the program (hello.go):

go run hello.go

Then open http://127.0.0.1:8080/ in browser.

BUGS

Report bugs to chaishushan@gmail.com.

Thanks!

Documentation

Overview

Package etcdfs file provides an implementation of the FileSystem interface based on the contents of a etcd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(c *EtcdClient) vfs.FileSystem

New returns a new FileSystem from the provided etcd. Wtcd keys should be forward slash-separated pathnames and not contain a leading slash.

Types

type EtcdClient

type EtcdClient struct {
	*clientv3.Client
}

func NewEtcdClient

func NewEtcdClient(endpoints []string, timeout time.Duration) (*EtcdClient, error)

func NewEtcdClientWithConfig

func NewEtcdClientWithConfig(cfg clientv3.Config) (*EtcdClient, error)

func (*EtcdClient) Clear

func (p *EtcdClient) Clear() error

func (*EtcdClient) Close

func (p *EtcdClient) Close() error

func (*EtcdClient) DelValues

func (p *EtcdClient) DelValues(keys ...string) error

func (*EtcdClient) DelValuesWithPrefix

func (p *EtcdClient) DelValuesWithPrefix(keyPrefixs ...string) error

func (*EtcdClient) Get

func (p *EtcdClient) Get(key string) (val string, ok bool)

func (*EtcdClient) GetAllValues

func (p *EtcdClient) GetAllValues() (map[string]string, error)

func (*EtcdClient) GetStructValue

func (p *EtcdClient) GetStructValue(keyPrefix string, out interface{}) error

func (*EtcdClient) GetValues

func (p *EtcdClient) GetValues(keys ...string) (map[string]string, error)

func (*EtcdClient) GetValuesByPrefix

func (p *EtcdClient) GetValuesByPrefix(keyPrefix string) (map[string]string, error)

func (*EtcdClient) Set

func (p *EtcdClient) Set(key, val string) error

func (*EtcdClient) SetStructValue

func (p *EtcdClient) SetStructValue(keyPrefix string, val interface{}) error

func (*EtcdClient) SetValues

func (p *EtcdClient) SetValues(m map[string]string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL