mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-11 18:32:50 +00:00
go pathing is a nightmare with app engine
This commit is contained in:
11
server.go
11
server.go
@@ -2,11 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"mywebsite/server/controller/api"
|
//local import paths relative to app.yaml file
|
||||||
"mywebsite/server/db"
|
"server/controller/api"
|
||||||
"mywebsite/server/route"
|
"server/db"
|
||||||
"mywebsite/server/utils"
|
"server/route"
|
||||||
|
"server/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"mywebsite/server/model/daily_sensor"
|
"server/model/daily_sensor"
|
||||||
"mywebsite/server/model/raw_sensor"
|
"server/model/raw_sensor"
|
||||||
)
|
)
|
||||||
|
|
||||||
// handle http request from sensors
|
// handle http request from sensors
|
||||||
|
|||||||
@@ -25,25 +25,29 @@ func Configure(d DatabaseInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Connect() {
|
func (d *Driver) Connect() {
|
||||||
// Connect to MongoDB
|
if (d.Info.URL != ""){
|
||||||
s, err := mgo.DialWithTimeout(d.Info.URL, 5*time.Second)
|
// Connect to MongoDB
|
||||||
|
s, err := mgo.DialWithTimeout(d.Info.URL, 5*time.Second)
|
||||||
if err != nil {
|
|
||||||
log.Println("MongoDB Driver Error", err)
|
if err != nil {
|
||||||
return
|
log.Println("MongoDB Driver Error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Session = s
|
||||||
|
|
||||||
|
// Prevents these errors: read tcp 127.0.0.1:27017: i/o timeout
|
||||||
|
d.Session.SetSocketTimeout(10 * time.Second)
|
||||||
|
|
||||||
|
// Check if is alive
|
||||||
|
if err = d.Session.Ping(); err != nil {
|
||||||
|
log.Println("Database Error", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Connected to database")
|
||||||
|
} else {
|
||||||
|
log.Println("Database not configured")
|
||||||
}
|
}
|
||||||
|
|
||||||
d.Session = s
|
|
||||||
|
|
||||||
// Prevents these errors: read tcp 127.0.0.1:27017: i/o timeout
|
|
||||||
d.Session.SetSocketTimeout(10 * time.Second)
|
|
||||||
|
|
||||||
// Check if is alive
|
|
||||||
if err = d.Session.Ping(); err != nil {
|
|
||||||
log.Println("Database Error", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("Connected to database")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) Connected() bool {
|
func (d *Driver) Connected() bool {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"mywebsite/server/db"
|
"server/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"mywebsite/server/db"
|
"server/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"mywebsite/server/controller"
|
"server/controller"
|
||||||
"mywebsite/server/controller/api"
|
"server/controller/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Routes() *httprouter.Router {
|
func Routes() *httprouter.Router {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"mywebsite/server/controller/api"
|
"server/controller/api"
|
||||||
"mywebsite/server/db"
|
"server/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
//structure for application configurations
|
//structure for application configurations
|
||||||
|
|||||||
Reference in New Issue
Block a user