1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-26 13:48:53 +08:00
Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
Drasko DRASKOVIC 2016-11-04 23:10:13 +01:00
parent c12a88d12f
commit d38ea79dde
11 changed files with 124 additions and 133 deletions

View File

@ -1,21 +1,21 @@
package clients
import (
"fmt"
"strings"
"time"
"log"
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
"strings"
"time"
"github.com/mainflux/mainflux/config"
"github.com/mainflux/mainflux/db"
"github.com/mainflux/mainflux/models"
"github.com/mainflux/mainflux/config"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/krylovsk/gosenml"
"gopkg.in/mgo.v2/bson"
mqtt "github.com/eclipse/paho.mqtt.golang"
)
type (
@ -75,7 +75,6 @@ func (mqc *MqttConn) MqttSub(cfg config.Config) {
WriteStatusChannel = make(chan ChannelWriteStatus)
}
/**
* WriteChannel()
* Generic function that updates the channel value.

View File

@ -34,7 +34,6 @@ type Config struct {
InfluxDatabase string
}
func (cfg *Config) Parse() {
var confFile string

View File

@ -12,19 +12,19 @@ import (
"encoding/json"
"fmt"
"log"
"time"
"strconv"
"time"
"github.com/mainflux/mainflux/clients"
"github.com/mainflux/mainflux/db"
"github.com/mainflux/mainflux/models"
"github.com/mainflux/mainflux/clients"
"github.com/satori/go.uuid"
"gopkg.in/mgo.v2/bson"
"io"
"net/http"
"io/ioutil"
"net/http"
"github.com/go-zoo/bone"
)
@ -127,7 +127,8 @@ func GetChannels(w http.ResponseWriter, r *http.Request) {
// Set default limit to -5
climit = -100
} else {
climit, err = strconv.Atoi(s); if err != nil {
climit, err = strconv.Atoi(s)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
str := `{"response": "wrong count limit"}`
io.WriteString(w, str)
@ -140,7 +141,8 @@ func GetChannels(w http.ResponseWriter, r *http.Request) {
// Set default limit to -5
vlimit = -100
} else {
vlimit, err = strconv.Atoi(s); if err != nil {
vlimit, err = strconv.Atoi(s)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
str := `{"response": "wrong value limit"}`
io.WriteString(w, str)
@ -177,7 +179,6 @@ func GetChannel(w http.ResponseWriter, r *http.Request) {
id := bone.GetValue(r, "channel_id")
var vlimit int
var err error
s := r.URL.Query().Get("vlimit")
@ -185,7 +186,8 @@ func GetChannel(w http.ResponseWriter, r *http.Request) {
// Set default limit to -5
vlimit = -5
} else {
vlimit, err = strconv.Atoi(s); if err != nil {
vlimit, err = strconv.Atoi(s)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
str := `{"response": "wrong limit"}`
io.WriteString(w, str)
@ -204,7 +206,6 @@ func GetChannel(w http.ResponseWriter, r *http.Request) {
return
}
w.WriteHeader(http.StatusOK)
res, err := json.Marshal(result)
if err != nil {
@ -290,5 +291,3 @@ func DeleteChannel(w http.ResponseWriter, r *http.Request) {
str := `{"response": "deleted", "id": "` + id + `"}`
io.WriteString(w, str)
}

View File

@ -21,8 +21,8 @@ import (
"gopkg.in/mgo.v2/bson"
"io"
"net/http"
"io/ioutil"
"net/http"
"github.com/go-zoo/bone"
)
@ -189,7 +189,6 @@ func UpdateDevice(w http.ResponseWriter, r *http.Request) {
}
*/
Db := db.MgoDb{}
Db.Init()
defer Db.Close()

12
main.go
View File

@ -9,17 +9,17 @@
package main
import (
"flag"
"fmt"
"os"
"strings"
"strconv"
"github.com/fatih/color"
"github.com/mainflux/mainflux/clients"
"github.com/mainflux/mainflux/config"
"github.com/mainflux/mainflux/db"
"github.com/mainflux/mainflux/servers"
"github.com/mainflux/mainflux/clients"
"github.com/fatih/color"
"os"
"runtime"
"flag"
"strconv"
"strings"
)
type MainfluxLite struct {

View File

@ -9,17 +9,15 @@
package servers
import (
"strconv"
"net/http"
"strconv"
"github.com/mainflux/mainflux/controllers"
"github.com/mainflux/mainflux/config"
"github.com/mainflux/mainflux/controllers"
"github.com/go-zoo/bone"
)
func HttpServer(cfg config.Config) {
mux := bone.New()

View File

@ -9,12 +9,12 @@
package servers
import (
"testing"
"time"
"log"
"os"
"net/http"
"net/http/httptest"
"os"
"testing"
"time"
"github.com/mainflux/mainflux/config"
"github.com/mainflux/mainflux/controllers"
@ -24,7 +24,6 @@ import (
"gopkg.in/mgo.v2"
)
func TestMain(m *testing.M) {
// We are in testing - notify the program
// so that it is not confused if some other commad line
@ -75,7 +74,6 @@ func TestServer(t *testing.T) {
var cfg config.Config
cfg.Parse()
// Create a request to pass to our handler. We don't have any query parameters for now, so we'll
// pass 'nil' as the third parameter.
req, err := http.NewRequest("GET", "/status", nil)
@ -102,4 +100,3 @@ func TestServer(t *testing.T) {
t.Errorf("handler returned unexpected body: got %v want %v", rr.Body.String(), expected)
}
}