From f6ec518814b21024b6de1256737de67529fc60d2 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Sat, 27 Dec 2014 18:29:18 -0800 Subject: [PATCH] removed mongodb --- api.go | 88 -------------------------------------------------- params.go | 36 ++------------------- params.yml | 9 ------ params_test.go | 24 +------------- 4 files changed, 3 insertions(+), 154 deletions(-) delete mode 100644 api.go diff --git a/api.go b/api.go deleted file mode 100644 index 5b878dd..0000000 --- a/api.go +++ /dev/null @@ -1,88 +0,0 @@ -package main - -import ( - "encoding/json" - "errors" - "fmt" - "net/http" - "strings" - - "gopkg.in/mgo.v2/bson" -) - -/* -Api structure - -/weblabs - POST: create a new weblab. The payload must be - { - "name": "web lab frendly name", - "cases": ["case_name_1", "case_name_2", ..., "case_name_n"], - "probabilities": [prob_1, prob_2, ..., prob_n], // the sum must be 1 - "private": false, - } - GET: - returns the list of all the created weblabs - -/weblabs/ - GET: returns the weblab as - -/weblabs//history - GET: get the history -*/ - -// the smallest value that makes two floats the same. -const epsilon float64 = 0.000000001 - -type Cases struct { - Name string `json:"name"` - Probability float64 `json:"probability"` -} - -type WeblabDefinition struct { - Id bson.ObjectId `json:"id"` - Name string `json:"name"` - Cases []*Cases `json:"cases"` - Private bool `json:"private"` -} - -func (w *WeblabDefinition) verifyCasesStructure() error { - names := make(map[string]bool) - for _, c := range w.Cases { - if c.Probability+epsilon < 0 { - return errors.New("probability cannot be less 0") - } - if c.Probability-epsilon > 1 { - return errors.New("probability cannot be greater 0") - } - c.Name = strings.Trim(c.Name, " \t\n\r") - if c.Name == "" { - return errors.New("weblab cannot have empty names") - } - names[c.Name] = true - } - if len(names) != len(w.Cases) { - return errors.New("multiple weblab cannot have the same name") - } - return nil -} - -func (w *WeblabDefinition) VerifyProbabilitySum() { - -} -func (w *WeblabDefinition) Verify() error { - - return nil -} - -func CreateNewWeblab(w http.ResponseWriter, request *http.Request) { - d := json.NewDecoder(request.Body) - wab := new(WeblabDefinition) - if err := d.Decode(d); err != nil { - w.WriteHeader(400) - fmt.Fprint(w, err.Error()) - return - } - wab.Id = bson.NewObjectId() - -} diff --git a/params.go b/params.go index 60b9110..3366edd 100644 --- a/params.go +++ b/params.go @@ -3,7 +3,6 @@ package main import ( "io/ioutil" - mgo "gopkg.in/mgo.v2" goyaml "gopkg.in/yaml.v2" ) @@ -12,15 +11,9 @@ const PARAM_FILE string = "params.yml" type Params struct { Port int `yaml:"port,omitempty"` Host string `yaml:"host,omitempty"` - Mongo *MongoParams `yaml:"mongo,omitempty"` - MongoClient *mgo.Session `yaml:"-"` - DB *mgo.Database `yaml:"-"` } -type MongoParams struct { - Url string `yaml:"url,omitempty"` - DatabaseName string `yaml:"database_name,omitempty"` -} + func (this *Params) LoadFromYamlFile(fileName string) error { data, err := ioutil.ReadFile(fileName) @@ -43,36 +36,14 @@ func (this *Params) LoadFromYamlData(data []byte) error { if p.Port > 0 { this.Port = p.Port } - if p.Mongo == nil { - return nil - } - if p.Mongo.Url != "" { - this.Mongo.Url = p.Mongo.Url - } - if p.Mongo.DatabaseName != "" { - this.Mongo.DatabaseName = p.Mongo.DatabaseName - } - if p.Mongo.DatabaseName != "" { - this.Mongo.DatabaseName = p.Mongo.DatabaseName - } return nil } -func (this *Params) initMongo() error { - var err error - this.MongoClient, err = mgo.Dial(this.Mongo.Url) - this.DB = this.MongoClient.DB(this.Mongo.DatabaseName) - return err -} func GetDefaultParams() *Params { - mongoParams := &MongoParams{ - Url: "localhost:27017", - DatabaseName: "union", - } - return &Params{7777, "localhost", mongoParams, nil, nil} + return &Params{7777, "localhost"} } var params = GetDefaultParams() @@ -81,7 +52,4 @@ func init() { if err := params.LoadFromYamlFile(PARAM_FILE); err != nil { panic(err) } - if err := params.initMongo(); err != nil { - panic(err) - } } diff --git a/params.yml b/params.yml index 97de88c..4f737f4 100644 --- a/params.yml +++ b/params.yml @@ -13,12 +13,3 @@ port: 1999 # service host: 0.0.0.0 #localhost - - -# all the params relative to mongodb -mongo: - # the url where to get mongodb - url: localhost:27017 - - # the name of the database to use - database_name: amazon_union diff --git a/params_test.go b/params_test.go index 1b4864d..9504909 100644 --- a/params_test.go +++ b/params_test.go @@ -11,20 +11,7 @@ port: 9999 host: 0.0.0.0 #localhost -# all the params relative to mongodb -mongo: - # the url where to get mongodb - url: localhost:1234 - - # the name of the database to use - database_name: geography - - # the name of the collection where all the street can be found - street_collection: quebec_street_map - - - # the collection where all the heat map point will be stored - heat_map_collection: quebec_heat_map # quebec_heat_map + ` func TestLoadFromYamlData(t *testing.T) { @@ -39,14 +26,5 @@ func TestLoadFromYamlData(t *testing.T) { if p.Host != "0.0.0.0" { t.Error("host") } - if p.Mongo.Url != "localhost:1234" { - t.Error("mongo.url") - } - if p.Mongo.Url != "localhost:1234" { - t.Error("mongo.url") - } - if p.Mongo.DatabaseName != "geography" { - t.Error("mongo.DatabaseName") - } }