mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
boom
This commit is contained in:
parent
c87f1d3924
commit
cb7b321240
@ -10,6 +10,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -31,6 +32,35 @@ func (ps Peers) Pick(id int64) string {
|
||||
return fmt.Sprintf("http://%s", addrs[rand.Intn(len(addrs))])
|
||||
}
|
||||
|
||||
// Set parses command line sets of names to ips formatted like:
|
||||
// a=1.1.1.1&a=1.1.1.2&b=2.2.2.2
|
||||
func (ps Peers) Set(s string) error {
|
||||
v, err := url.ParseQuery(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for k, v := range v {
|
||||
id, err := strconv.ParseInt(k, 16, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ps[id] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps Peers) String() string {
|
||||
return "todo"
|
||||
}
|
||||
|
||||
func (ps Peers) Ids() []int64 {
|
||||
var ids []int64
|
||||
for id, _ := range ps {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
var errClosed = errors.New("etcdhttp: client closed connection")
|
||||
|
||||
const DefaultTimeout = 500 * time.Millisecond
|
||||
|
29
main.go
29
main.go
@ -4,6 +4,8 @@ import (
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
etcdserver "github.com/coreos/etcd/etcdserver2"
|
||||
"github.com/coreos/etcd/etcdserver2/etcdhttp"
|
||||
@ -12,25 +14,34 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
id = flag.String("id", "default", "The id of this server")
|
||||
fid = flag.String("id", "default", "Id of this server")
|
||||
timeout = flag.Duration("timeout", 10*time.Second, "Request Timeout")
|
||||
laddr = flag.String("l", ":8080", "HTTP service address (e.g., ':8080')")
|
||||
|
||||
peers = etcdhttp.Peers{}
|
||||
)
|
||||
|
||||
func main() {
|
||||
const V2Prefix = "/v2"
|
||||
func init() {
|
||||
flag.Var(peers, "peers", "your peers")
|
||||
}
|
||||
|
||||
peers := etcdhttp.Discover(V2Prefix, peerips)
|
||||
n := raft.Start(*id, peers.Ids())
|
||||
func main() {
|
||||
id, err := strconv.ParseInt(*fid, 16, 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
n := raft.Start(id, peers.Ids())
|
||||
s := &etcdserver.Server{
|
||||
Node: n,
|
||||
Save: func(st raftpb.State, ents []raftpb.Entry) {}, // TODO: use wal
|
||||
Send: etcdhttp.Sender(V2Prefix),
|
||||
Send: etcdhttp.Sender(peers),
|
||||
}
|
||||
etcdserver.Start(s)
|
||||
h := &etcdhttp.Handler{
|
||||
Timeout: timeout,
|
||||
Timeout: *timeout,
|
||||
Server: s,
|
||||
Peers: peers,
|
||||
}
|
||||
http.Handle(V2Prefix, http.StripPrefix(V2Prefix, h))
|
||||
http.Handle("/", h)
|
||||
log.Fatal(http.ListenAndServe(*laddr, nil))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user