mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcd: replace -proxy-mode with -proxy
This commit is contained in:
parent
fcf50e756d
commit
afce2948d2
2
Procfile
2
Procfile
@ -2,4 +2,4 @@
|
|||||||
etcd1: ./etcd -id 0x1 -bind-addr 127.0.0.1:4001 -peer-bind-addr :7001 -peers '0x1=localhost:7001&0x2=localhost:7002&0x3=localhost:7003'
|
etcd1: ./etcd -id 0x1 -bind-addr 127.0.0.1:4001 -peer-bind-addr :7001 -peers '0x1=localhost:7001&0x2=localhost:7002&0x3=localhost:7003'
|
||||||
etcd2: ./etcd -id 0x2 -bind-addr 127.0.0.1:4002 -peer-bind-addr :7002 -peers '0x1=localhost:7001&0x2=localhost:7002&0x3=localhost:7003'
|
etcd2: ./etcd -id 0x2 -bind-addr 127.0.0.1:4002 -peer-bind-addr :7002 -peers '0x1=localhost:7001&0x2=localhost:7002&0x3=localhost:7003'
|
||||||
etcd3: ./etcd -id 0x3 -bind-addr 127.0.0.1:4003 -peer-bind-addr :7003 -peers '0x1=localhost:7001&0x2=localhost:7002&0x3=localhost:7003'
|
etcd3: ./etcd -id 0x3 -bind-addr 127.0.0.1:4003 -peer-bind-addr :7003 -peers '0x1=localhost:7001&0x2=localhost:7002&0x3=localhost:7003'
|
||||||
proxy: ./etcd -proxy-mode -bind-addr 127.0.0.1:8080 -peers '0x1=localhost:7001&0x2=localhost:7002&0x3=localhost:7003'
|
proxy: ./etcd -proxy=on -bind-addr 127.0.0.1:8080 -peers '0x1=localhost:7001&0x2=localhost:7002&0x3=localhost:7003'
|
||||||
|
42
main.go
42
main.go
@ -24,6 +24,9 @@ import (
|
|||||||
const (
|
const (
|
||||||
// the owner can make/remove files inside the directory
|
// the owner can make/remove files inside the directory
|
||||||
privateDirMode = 0700
|
privateDirMode = 0700
|
||||||
|
|
||||||
|
proxyFlagValueOff = "off"
|
||||||
|
proxyFlagValueOn = "on"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -31,18 +34,25 @@ var (
|
|||||||
timeout = flag.Duration("timeout", 10*time.Second, "Request Timeout")
|
timeout = flag.Duration("timeout", 10*time.Second, "Request Timeout")
|
||||||
paddr = flag.String("peer-bind-addr", ":7001", "Peer service address (e.g., ':7001')")
|
paddr = flag.String("peer-bind-addr", ":7001", "Peer service address (e.g., ':7001')")
|
||||||
dir = flag.String("data-dir", "", "Path to the data directory")
|
dir = flag.String("data-dir", "", "Path to the data directory")
|
||||||
proxyMode = flag.Bool("proxy-mode", false, "Forward HTTP requests to peers, do not participate in raft.")
|
|
||||||
snapCount = flag.Int64("snapshot-count", etcdserver.DefaultSnapCount, "Number of committed transactions to trigger a snapshot")
|
snapCount = flag.Int64("snapshot-count", etcdserver.DefaultSnapCount, "Number of committed transactions to trigger a snapshot")
|
||||||
|
|
||||||
peers = &etcdhttp.Peers{}
|
peers = &etcdhttp.Peers{}
|
||||||
addrs = &Addrs{}
|
addrs = &Addrs{}
|
||||||
|
proxyFlag = new(ProxyFlag)
|
||||||
|
|
||||||
|
proxyFlagValues = []string{
|
||||||
|
proxyFlagValueOff,
|
||||||
|
proxyFlagValueOn,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.Var(peers, "peers", "your peers")
|
flag.Var(peers, "peers", "your peers")
|
||||||
flag.Var(addrs, "bind-addr", "List of HTTP service addresses (e.g., '127.0.0.1:4001,10.0.0.1:8080')")
|
flag.Var(addrs, "bind-addr", "List of HTTP service addresses (e.g., '127.0.0.1:4001,10.0.0.1:8080')")
|
||||||
|
flag.Var(proxyFlag, "proxy", fmt.Sprintf("Valid values include %s", strings.Join(proxyFlagValues, ", ")))
|
||||||
peers.Set("0x1=localhost:8080")
|
peers.Set("0x1=localhost:8080")
|
||||||
addrs.Set("127.0.0.1:4001")
|
addrs.Set("127.0.0.1:4001")
|
||||||
|
proxyFlag.Set(proxyFlagValueOff)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -50,10 +60,10 @@ func main() {
|
|||||||
|
|
||||||
setFlagsFromEnv()
|
setFlagsFromEnv()
|
||||||
|
|
||||||
if *proxyMode {
|
if string(*proxyFlag) == proxyFlagValueOff {
|
||||||
startProxy()
|
|
||||||
} else {
|
|
||||||
startEtcd()
|
startEtcd()
|
||||||
|
} else {
|
||||||
|
startProxy()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block indefinitely
|
// Block indefinitely
|
||||||
@ -201,6 +211,26 @@ func (as *Addrs) String() string {
|
|||||||
return strings.Join(*as, ",")
|
return strings.Join(*as, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProxyFlag implements the flag.Value interface.
|
||||||
|
type ProxyFlag string
|
||||||
|
|
||||||
|
// Set verifies the argument to be a valid member of proxyFlagValues
|
||||||
|
// before setting the underlying flag value.
|
||||||
|
func (pf *ProxyFlag) Set(s string) error {
|
||||||
|
for _, v := range proxyFlagValues {
|
||||||
|
if s == v {
|
||||||
|
*pf = ProxyFlag(s)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.New("invalid value")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pf *ProxyFlag) String() string {
|
||||||
|
return string(*pf)
|
||||||
|
}
|
||||||
|
|
||||||
// setFlagsFromEnv parses all registered flags in the global flagset,
|
// setFlagsFromEnv parses all registered flags in the global flagset,
|
||||||
// and if they are not already set it attempts to set their values from
|
// and if they are not already set it attempts to set their values from
|
||||||
// environment variables. Environment variables take the name of the flag but
|
// environment variables. Environment variables take the name of the flag but
|
||||||
|
23
main_test.go
23
main_test.go
@ -41,3 +41,26 @@ func TestSetFlagsFromEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProxyFlagSet(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
val string
|
||||||
|
pass bool
|
||||||
|
}{
|
||||||
|
// known values
|
||||||
|
{"on", true},
|
||||||
|
{"off", true},
|
||||||
|
|
||||||
|
// unrecognized values
|
||||||
|
{"foo", false},
|
||||||
|
{"", false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tt := range tests {
|
||||||
|
pf := new(ProxyFlag)
|
||||||
|
err := pf.Set(tt.val)
|
||||||
|
if tt.pass != (err == nil) {
|
||||||
|
t.Errorf("#%d: want pass=%t, but got err=%v", i, tt.pass, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user