import ( "encoding/base64" "encoding/json" "fmt" "github.com/ManikDV/storage/db" "github.com/ManikDV/storage/utils" "github.com/gorilla/mux" "gopkg.in/mgo.v2/bson" "io/ioutil" "net/http" "strconv" "time" ) var log = utils.SetUpLogger("api") func Ping(w http.ResponseWriter, r *http.Request) { log.Info("Ping") responseMessage := "Pong!" w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) if err := json.NewEncoder(w).Encode(responseMessage); err != nil { log.Error(err) } } func CreateSign(w http.ResponseWriter, r *http.Request) { log.Info("CreateSign")
package main import ( "net/http" "database/sql" "github.com/ManikDV/storage/api" "github.com/ManikDV/storage/db" "github.com/ManikDV/storage/utils" ) type DbServer struct { db *sql.DB } var log = utils.SetUpLogger("storage") func PrintClusterInfo() { clusterStats, err := db.GetClusterStats() if err != nil { log.Error(err) return } log.Info("Mongoses:") for _, mongos := range clusterStats.Mongoses { log.Infof("\tId:%s, ping: %s, uptime:%d, isWaiting:%t \n", mongos.Id, mongos.Ping, mongos.Up, mongos.Waiting) } log.Info("Shards:") for _, shard := range clusterStats.Shards {
package db import ( "errors" "github.com/ManikDV/storage/utils" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" ) var ( Session *mgo.Session Mongo *mgo.DialInfo log = utils.SetUpLogger("db") AvgWriteQueryTime int64 = 0 AvgReadQueryTime int64 = 0 LastWriteQueryTime int64 = 0 LastReadQueryTime int64 = 0 ) func InitDb() { log.Info("DB initialization started") // Setup DB connection mongo, err := mgo.ParseURL(utils.Conf.DBUrl) if err != nil { panic(err) } session, err := mgo.Dial(utils.Conf.DBUrl)