aboutsummaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-12-02 01:54:05 -0800
committerChris Lu <chris.lu@gmail.com>2013-12-02 01:54:05 -0800
commita234789c5993b24c536488c1ea0ac0d58374ce31 (patch)
tree2b5b54c724d24ae23a1ed098f2c38bc8407715ef /go
parentc38eee73ca752b670adc0717b3436c5e9a49c4f8 (diff)
downloadseaweedfs-a234789c5993b24c536488c1ea0ac0d58374ce31.tar.xz
seaweedfs-a234789c5993b24c536488c1ea0ac0d58374ce31.zip
switch to glog debugging
Diffstat (limited to 'go')
-rw-r--r--go/weed/weed.go106
-rw-r--r--go/weed/weed_server/common.go6
2 files changed, 2 insertions, 110 deletions
diff --git a/go/weed/weed.go b/go/weed/weed.go
index 26a009b4b..896b8e237 100644
--- a/go/weed/weed.go
+++ b/go/weed/weed.go
@@ -2,15 +2,11 @@ package main
import (
"code.google.com/p/weed-fs/go/glog"
- "encoding/json"
"flag"
"fmt"
"io"
"math/rand"
- "net"
- "net/http"
"os"
- "path/filepath"
"strings"
"sync"
"text/template"
@@ -175,106 +171,6 @@ func exit() {
os.Exit(exitStatus)
}
-func exitIfErrors() {
- if exitStatus != 0 {
- exit()
- }
-}
-
-func writeJson(w http.ResponseWriter, r *http.Request, obj interface{}) (err error) {
- w.Header().Set("Content-Type", "application/javascript")
- var bytes []byte
- if r.FormValue("pretty") != "" {
- bytes, err = json.MarshalIndent(obj, "", " ")
- } else {
- bytes, err = json.Marshal(obj)
- }
- if err != nil {
- return
- }
- callback := r.FormValue("callback")
- if callback == "" {
- _, err = w.Write(bytes)
- } else {
- if _, err = w.Write([]uint8(callback)); err != nil {
- return
- }
- if _, err = w.Write([]uint8("(")); err != nil {
- return
- }
- fmt.Fprint(w, string(bytes))
- if _, err = w.Write([]uint8(")")); err != nil {
- return
- }
- }
- return
-}
-
-// wrapper for writeJson - just logs errors
-func writeJsonQuiet(w http.ResponseWriter, r *http.Request, obj interface{}) {
- if err := writeJson(w, r, obj); err != nil {
- glog.V(0).Infof("error writing JSON %s: %s", obj, err.Error())
- }
-}
-func writeJsonError(w http.ResponseWriter, r *http.Request, err error) {
- m := make(map[string]interface{})
- m["error"] = err.Error()
- writeJsonQuiet(w, r, m)
-}
-
func debug(params ...interface{}) {
- if *IsDebug {
- glog.V(0).Infoln(params)
- }
-}
-func secure(whiteList []string, f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
- return func(w http.ResponseWriter, r *http.Request) {
- if len(whiteList) == 0 {
- f(w, r)
- return
- }
- host, _, err := net.SplitHostPort(r.RemoteAddr)
- if err == nil {
- for _, ip := range whiteList {
- if ip == host {
- f(w, r)
- return
- }
- }
- }
- writeJsonQuiet(w, r, map[string]interface{}{"error": "No write permisson from " + host})
- }
-}
-
-func parseURLPath(path string) (vid, fid, filename, ext string, isVolumeIdOnly bool) {
- switch strings.Count(path, "/") {
- case 3:
- parts := strings.Split(path, "/")
- vid, fid, filename = parts[1], parts[2], parts[3]
- ext = filepath.Ext(filename)
- case 2:
- parts := strings.Split(path, "/")
- vid, fid = parts[1], parts[2]
- dotIndex := strings.LastIndex(fid, ".")
- if dotIndex > 0 {
- ext = fid[dotIndex:]
- fid = fid[0:dotIndex]
- }
- default:
- sepIndex := strings.LastIndex(path, "/")
- commaIndex := strings.LastIndex(path[sepIndex:], ",")
- if commaIndex <= 0 {
- vid, isVolumeIdOnly = path[sepIndex+1:], true
- return
- }
- dotIndex := strings.LastIndex(path[sepIndex:], ".")
- vid = path[sepIndex+1 : commaIndex]
- fid = path[commaIndex+1:]
- ext = ""
- if dotIndex > 0 {
- fid = path[commaIndex+1 : dotIndex]
- ext = path[dotIndex:]
- }
- }
- return
+ glog.V(4).Infoln(params)
}
diff --git a/go/weed/weed_server/common.go b/go/weed/weed_server/common.go
index 929bf592d..d0d52f488 100644
--- a/go/weed/weed_server/common.go
+++ b/go/weed/weed_server/common.go
@@ -14,8 +14,6 @@ import (
"strings"
)
-var IsDebug *bool
-
func writeJson(w http.ResponseWriter, r *http.Request, obj interface{}) (err error) {
w.Header().Set("Content-Type", "application/javascript")
var bytes []byte
@@ -58,9 +56,7 @@ func writeJsonError(w http.ResponseWriter, r *http.Request, err error) {
}
func debug(params ...interface{}) {
- if *IsDebug {
- glog.V(0).Infoln(params)
- }
+ glog.V(4).Infoln(params)
}
func secure(whiteList []string, f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {