-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
243 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
vendor/ | ||
.idea/ |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/aerogear/aerogear-metrics-api/pkg/web" | ||
"github.com/aerogear/aerogear-metrics-api/pkg/dao" | ||
"github.com/aerogear/aerogear-metrics-api/pkg/mobile" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
router := web.NewRouter() | ||
db, err := dao.Connect() | ||
if err != nil{ | ||
panic("failed to connect to sql database : "+ err.Error()) | ||
} | ||
defer db.Close() | ||
metricDao := dao.NewMetricsDAO(db) | ||
|
||
//metrics route | ||
{ | ||
metricsService := mobile.NewMetricsService(metricDao) | ||
metricsHandler := web.NewMetricsHandler(metricsService) | ||
web.MetricsRoute(router,metricsHandler) | ||
} | ||
//health route | ||
{ | ||
healthHandler := web.NewHealthHandler() | ||
web.HealthzRoute(router,healthHandler) | ||
} | ||
|
||
//start | ||
if err := http.ListenAndServe(":3000",router); err != nil{ | ||
panic("failed to start " + err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dao | ||
|
||
import "database/sql" | ||
|
||
|
||
var db *sql.DB | ||
|
||
func Connect()(*sql.DB,error){ | ||
if db != nil{ | ||
return db,nil | ||
} | ||
//connection logic | ||
return nil,nil | ||
} | ||
|
||
func Disconnect()error{ | ||
if nil != db{ | ||
return db.Close() | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package mobile | ||
|
||
|
||
// MetricCreator defines how a metric can be created | ||
type MetricCreator interface{ | ||
Create(m Metric)(Metric,error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package mobile | ||
|
||
import ( | ||
"errors" | ||
|
||
) | ||
|
||
type MetricsService struct { | ||
mdao MetricCreator | ||
} | ||
|
||
func NewMetricsService(dao MetricCreator)*MetricsService{ | ||
return &MetricsService{mdao:dao} | ||
} | ||
|
||
|
||
|
||
func (m MetricsService) Create(metric Metric) (Metric, error) { | ||
return metric, errors.New("This is an error") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package models | ||
package mobile | ||
|
||
import "time" | ||
|
||
// Metric struct is what the client payload should be parsed into | ||
type AppConfig struct { | ||
DBConnectionString string | ||
} | ||
|
||
// ClientMetric struct is what the client payload should be parsed into | ||
// Need to figure out how to structure this | ||
type Metric struct { | ||
Timestamp time.Time `json:"timestamp"` | ||
ClientID string `json:"clientId"` | ||
Data interface{} `json:"data"` | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package web | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
|
||
) | ||
|
||
// not reusable type so make it package local | ||
|
||
type healthResponse struct { | ||
Timestamp time.Time `json:"time"` | ||
Status string `json:"status"` | ||
} | ||
|
||
type healthHandler struct{ | ||
|
||
} | ||
|
||
func NewHealthHandler()*healthHandler{ | ||
return &healthHandler{} | ||
} | ||
|
||
func (hh *healthHandler) Healthz(w http.ResponseWriter, r *http.Request) { | ||
status := healthResponse{ | ||
Timestamp: time.Now().UTC(), | ||
Status: "ok", | ||
} | ||
|
||
if err := withJSON(w, 200, status); err != nil{ | ||
http.Error(w,err.Error(),http.StatusInternalServerError) | ||
return | ||
} | ||
} | ||
|
||
func (hh *healthHandler)Ping(w http.ResponseWriter, r *http.Request) { | ||
|
||
} |
Oops, something went wrong.