1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-11 18:32:50 +00:00

getting close to finishing temperature data api

This commit is contained in:
2016-05-17 23:26:15 -05:00
parent 6627cb4cd6
commit b6d5854250
16 changed files with 693 additions and 86 deletions

61
main.go
View File

@@ -1,27 +1,66 @@
package main
import (
"encoding/json"
"fmt"
//"github.com/julienschmidt/httprouter"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/mgerb42/mywebsite/model"
"github.com/mgerb42/mywebsite/controller/api"
"github.com/mgerb42/mywebsite/db"
"github.com/mgerb42/mywebsite/route"
)
//structure for application configurations
type Config struct {
Database db.DatabaseInfo `json:"database"`
Api api.ApiInfo `json:"api"`
Server ServerConfig `json:"server"`
}
//configuration settings for the web
type ServerConfig struct {
Port string `json:"port"`
}
func main() {
s := model.NewSession()
configurations := readConfig()
s.TestStore("Mit", "G")
db.Configure(configurations.Database)
api.Configure(configurations.Api)
var p []model.Person
db.Mongo.Connect()
p = s.SearchName("Mit")
fmt.Println("Query: ")
fmt.Println(p[0].LastName)
log.Fatal(http.ListenAndServe(":8080", route.Routes()))
log.Println("Starting Server...")
log.Println(http.ListenAndServe(":"+configurations.Server.Port, route.Routes()))
}
//read the config file and return JsonObject struct
func readConfig() Config {
log.Println("Reading config file...")
file, e := ioutil.ReadFile("./config.json")
if e != nil {
fmt.Printf("File error: %v\n", e)
os.Exit(1)
}
fmt.Printf("%s\n", string(file))
//m := new(Dispatch)
//var m interface{}
var result Config
err := json.Unmarshal(file, &result)
if err != nil {
fmt.Println(err)
}
return result
}