-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Config struct to configure Server
- Loading branch information
Showing
6 changed files
with
166 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
Copyright 2018 Banco Bilbao Vizcaya Argentaria, S.A. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package server | ||
|
||
import ( | ||
"net" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type Config struct { | ||
// Unique name for this node. It identifies itself both in raft and | ||
// gossip clusters. If not set, fallback to hostname. | ||
NodeID string | ||
|
||
// HTTP server bind address/port. | ||
HttpAddr string | ||
|
||
// Raft communication bind address/port. | ||
RaftAddr string | ||
|
||
// Raft management server bind address/port. Useful to join the cluster | ||
// and get cluster information. | ||
MgmtAddr string | ||
|
||
// List of raft nodes, through which a cluster can be joined | ||
// (protocol://host:port). | ||
RaftJoinAddr []string | ||
|
||
// Path to storage directory. | ||
DBPath string | ||
|
||
// Path to Raft storage directory. | ||
RaftPath string | ||
|
||
// Gossip management server bind address/port. | ||
GossipAddr string | ||
|
||
// List of nodes, through which a gossip cluster can be joined (protocol://host:port). | ||
GossipJoinAddr []string | ||
|
||
// Path to the private key file used to sign snapshots. | ||
PrivateKeyPath string | ||
|
||
// Enables profiling endpoint. | ||
EnableProfiling bool | ||
|
||
// Enables tampering endpoint. | ||
EnableTampering bool | ||
} | ||
|
||
func DefaultConfig() *Config { | ||
hostname, _ := os.Hostname() | ||
currentDir := getCurrentDir() | ||
return &Config{ | ||
NodeID: hostname, | ||
HttpAddr: "127.0.0.1:8080", | ||
RaftAddr: "127.0.0.1:9000", | ||
MgmtAddr: "127.0.0.1:8090", | ||
RaftJoinAddr: []string{}, | ||
GossipAddr: "127.0.0.1:9100", | ||
GossipJoinAddr: []string{}, | ||
DBPath: currentDir + "/data", | ||
RaftPath: currentDir + "/raft", | ||
EnableProfiling: false, | ||
EnableTampering: false, | ||
} | ||
} | ||
|
||
func getCurrentDir() string { | ||
ex, err := os.Executable() | ||
if err != nil { | ||
panic(err) | ||
} | ||
exPath := filepath.Dir(ex) | ||
return exPath | ||
} | ||
|
||
// AddrParts returns the parts of and address/port. | ||
func addrParts(address string) (string, int, error) { | ||
_, _, err := net.SplitHostPort(address) | ||
if err != nil { | ||
return "", 0, err | ||
} | ||
|
||
addr, err := net.ResolveTCPAddr("tcp", address) | ||
if err != nil { | ||
return "", 0, err | ||
} | ||
|
||
return addr.IP.String(), addr.Port, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.