aboutsummaryrefslogtreecommitdiff
path: root/weed-fs/src/pkg
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2012-08-23 20:56:09 -0700
committerChris Lu <chris.lu@gmail.com>2012-08-23 20:56:09 -0700
commit0121f35c12e9a89b09044bf02ec5a39d6ae0bce9 (patch)
treecb846daa68c9d22853e115b0cc9fda78c40789e6 /weed-fs/src/pkg
parent0109cc0e30df35a13c775c209b09f41bd4d661fe (diff)
downloadseaweedfs-0121f35c12e9a89b09044bf02ec5a39d6ae0bce9.tar.xz
seaweedfs-0121f35c12e9a89b09044bf02ec5a39d6ae0bce9.zip
starting a shell
Diffstat (limited to 'weed-fs/src/pkg')
-rw-r--r--weed-fs/src/pkg/topology/data_center.go6
-rw-r--r--weed-fs/src/pkg/topology/node.go16
-rw-r--r--weed-fs/src/pkg/topology/rack.go10
-rw-r--r--weed-fs/src/pkg/util/config.go128
4 files changed, 160 insertions, 0 deletions
diff --git a/weed-fs/src/pkg/topology/data_center.go b/weed-fs/src/pkg/topology/data_center.go
new file mode 100644
index 000000000..022f733cc
--- /dev/null
+++ b/weed-fs/src/pkg/topology/data_center.go
@@ -0,0 +1,6 @@
+package topology
+
+import (
+
+)
+
diff --git a/weed-fs/src/pkg/topology/node.go b/weed-fs/src/pkg/topology/node.go
new file mode 100644
index 000000000..cf48b0d67
--- /dev/null
+++ b/weed-fs/src/pkg/topology/node.go
@@ -0,0 +1,16 @@
+package topology
+
+import (
+
+)
+
+type VolumeInfo struct {
+ Id uint32
+ Size int64
+}
+type Node struct {
+ volumes map[uint64]VolumeInfo
+ volumeLimit int
+ Port int
+ PublicUrl string
+}
diff --git a/weed-fs/src/pkg/topology/rack.go b/weed-fs/src/pkg/topology/rack.go
new file mode 100644
index 000000000..69895a243
--- /dev/null
+++ b/weed-fs/src/pkg/topology/rack.go
@@ -0,0 +1,10 @@
+package topology
+
+import (
+
+)
+
+type Rack struct {
+ nodes map[uint64]*Node
+ IpRanges []string
+}
diff --git a/weed-fs/src/pkg/util/config.go b/weed-fs/src/pkg/util/config.go
new file mode 100644
index 000000000..6ac8a3a65
--- /dev/null
+++ b/weed-fs/src/pkg/util/config.go
@@ -0,0 +1,128 @@
+// Copyright 2011 Numerotron Inc.
+// Use of this source code is governed by an MIT-style license
+// that can be found in the LICENSE file.
+//
+// Developed at www.stathat.com by Patrick Crosby
+// Contact us on twitter with any questions: twitter.com/stat_hat
+
+// The jconfig package provides a simple, basic configuration file parser using JSON.
+package util
+
+import (
+ "bytes"
+ "encoding/json"
+ "log"
+ "os"
+)
+
+type Config struct {
+ data map[string]interface{}
+ filename string
+}
+
+func newConfig() *Config {
+ result := new(Config)
+ result.data = make(map[string]interface{})
+ return result
+}
+
+// Loads config information from a JSON file
+func LoadConfig(filename string) *Config {
+ result := newConfig()
+ result.filename = filename
+ err := result.parse()
+ if err != nil {
+ log.Fatalf("error loading config file %s: %s", filename, err)
+ }
+ return result
+}
+
+// Loads config information from a JSON string
+func LoadConfigString(s string) *Config {
+ result := newConfig()
+ err := json.Unmarshal([]byte(s), &result.data)
+ if err != nil {
+ log.Fatalf("error parsing config string %s: %s", s, err)
+ }
+ return result
+}
+
+func (c *Config) StringMerge(s string) {
+ next := LoadConfigString(s)
+ c.merge(next.data)
+}
+
+func (c *Config) LoadMerge(filename string) {
+ next := LoadConfig(filename)
+ c.merge(next.data)
+}
+
+func (c *Config) merge(ndata map[string]interface{}) {
+ for k, v := range ndata {
+ c.data[k] = v
+ }
+}
+
+func (c *Config) parse() error {
+ f, err := os.Open(c.filename)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ b := new(bytes.Buffer)
+ _, err = b.ReadFrom(f)
+ if err != nil {
+ return err
+ }
+ err = json.Unmarshal(b.Bytes(), &c.data)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// Returns a string for the config variable key
+func (c *Config) GetString(key string) string {
+ result, present := c.data[key]
+ if !present {
+ return ""
+ }
+ return result.(string)
+}
+
+// Returns an int for the config variable key
+func (c *Config) GetInt(key string) int {
+ x, ok := c.data[key]
+ if !ok {
+ return -1
+ }
+ return int(x.(float64))
+}
+
+// Returns a float for the config variable key
+func (c *Config) GetFloat(key string) float64 {
+ x, ok := c.data[key]
+ if !ok {
+ return -1
+ }
+ return x.(float64)
+}
+
+// Returns a bool for the config variable key
+func (c *Config) GetBool(key string) bool {
+ x, ok := c.data[key]
+ if !ok {
+ return false
+ }
+ return x.(bool)
+}
+
+// Returns an array for the config variable key
+func (c *Config) GetArray(key string) []interface{} {
+ result, present := c.data[key]
+ if !present {
+ return []interface{}(nil)
+ }
+ return result.([]interface{})
+}