From 022fea22e2b217eba7cfc6fe04283ecacac2e1a1 Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Tue, 13 Mar 2018 15:04:26 +1100 Subject: [PATCH] init projecty --- .gitignore | 2 + Gopkg.lock | 73 ++++++++++++++++++++++++++++++++++++ Gopkg.toml | 38 +++++++++++++++++++ config.yaml | 22 +++++++++++ controllers/configuration.go | 9 +++++ main.go | 35 +++++++++++++++++ models/configuration.go | 33 ++++++++++++++++ request_objects/init_db.go | 7 ++++ 8 files changed, 219 insertions(+) create mode 100644 .gitignore create mode 100644 Gopkg.lock create mode 100644 Gopkg.toml create mode 100644 config.yaml create mode 100644 controllers/configuration.go create mode 100644 main.go create mode 100644 models/configuration.go create mode 100644 request_objects/init_db.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b92fce --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +next-dashboard +vendor diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000..66ab780 --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,73 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + name = "github.com/gin-contrib/sse" + packages = ["."] + revision = "22d885f9ecc78bf4ee5d72b937e4bbcdc58e8cae" + +[[projects]] + name = "github.com/gin-gonic/gin" + packages = [ + ".", + "binding", + "render" + ] + revision = "d459835d2b077e44f7c9b453505ee29881d5d12d" + version = "v1.2" + +[[projects]] + name = "github.com/golang/protobuf" + packages = ["proto"] + revision = "925541529c1fa6821df4e44ce2723319eb2be768" + version = "v1.0.0" + +[[projects]] + name = "github.com/jinzhu/gorm" + packages = ["."] + revision = "6ed508ec6a4ecb3531899a69cbc746ccf65a4166" + version = "v1.9.1" + +[[projects]] + branch = "master" + name = "github.com/jinzhu/inflection" + packages = ["."] + revision = "04140366298a54a039076d798123ffa108fff46c" + +[[projects]] + name = "github.com/mattn/go-isatty" + packages = ["."] + revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" + version = "v0.0.3" + +[[projects]] + name = "github.com/ugorji/go" + packages = ["codec"] + revision = "9831f2c3ac1068a78f50999a30db84270f647af6" + version = "v1.1" + +[[projects]] + branch = "master" + name = "golang.org/x/sys" + packages = ["unix"] + revision = "c28acc882ebcbfbe8ce9f0f14b9ac26ee138dd51" + +[[projects]] + name = "gopkg.in/go-playground/validator.v8" + packages = ["."] + revision = "5f1438d3fca68893a817e4a66806cea46a9e4ebf" + version = "v8.18.2" + +[[projects]] + name = "gopkg.in/yaml.v2" + packages = ["."] + revision = "7f97868eec74b32b0982dd158a51a446d1da7eb5" + version = "v2.1.1" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "86568bef8fd4f3101b0a69d615c6fa4ed13082ce6d10af3b5d8d91d90f7c7c35" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000..ecc013a --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,38 @@ +# Gopkg.toml example +# +# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + + +[[constraint]] + name = "github.com/gin-gonic/gin" + version = "1.2.0" + +[[constraint]] + name = "github.com/jinzhu/gorm" + version = "1.9.1" + +[prune] + go-tests = true + unused-packages = true diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..ef713f9 --- /dev/null +++ b/config.yaml @@ -0,0 +1,22 @@ +config: + name: dex-prod + frequency: 5s + db: + url: 'xxx' + type: postgres + checks: + - table: contracts + field: someuuid + value: xxxxxx + - table: dispatches + - table: resources + - table: contracts + http: + checks: + - url: https://api.dev.dexdev.greensync.xyz/health/contracts + - url: https://docs.dev.dexdev.greensync.xyz/health + - url: http://app.dev.dexdev.greensync.xyz/health + event: + checks: + - name: 'contracts' + diff --git a/controllers/configuration.go b/controllers/configuration.go new file mode 100644 index 0000000..864e85d --- /dev/null +++ b/controllers/configuration.go @@ -0,0 +1,9 @@ +package controllers + +import ( + "github.com/gin-gonic/gin" +) + +func InitDB(c *gin.Context) { + +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..c46cbd3 --- /dev/null +++ b/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "io/ioutil" + + "github.com/sirupsen/logrus" + "gopkg.in/yaml.v2" + + "github.com/gin-gonic/gin" + "github.com/wahyd4/next-dashboard/controllers" + "github.com/wahyd4/next-dashboard/models" +) + +func init() { + content, err := ioutil.ReadFile("./config.yaml") + if err != nil { + logrus.Fatalf("Can't read config file: %v", err) + } + + var config models.Configuration + err = yaml.Unmarshal(content, &config) + + if err != nil { + logrus.Fatalf("Can't unmashal yaml config: %v", err) + } + + spew.Dump() +} + +func main() { + server := gin.Default() + server.POST("/configurations/init-db", controllers.InitDB) + + server.Run() +} diff --git a/models/configuration.go b/models/configuration.go new file mode 100644 index 0000000..2efddc0 --- /dev/null +++ b/models/configuration.go @@ -0,0 +1,33 @@ +package models + +import "github.com/jinzhu/gorm" + +type Configuration struct { + gorm.Model + Name string `json:"name"` + Frequency string `json:"frequency"` + DB *DBConfig `json:"db"` + HTTP *HTTPConfig `json:"http"` + Event *EventConfig `json:"event"` +} + +type DBConfig struct { + URL string `json:"url"` + DBType string `json:"dbType"` +} + +type HTTPConfig struct { + Checks []*HTTPCheck `json:"check"` +} + +type HTTPCheck struct { + URL string `json:"url"` +} + +type EventConfig struct { + Checks []*EventCheck `json:"checks"` +} + +type EventCheck struct { + Name string `json:"name"` +} diff --git a/request_objects/init_db.go b/request_objects/init_db.go new file mode 100644 index 0000000..f50439c --- /dev/null +++ b/request_objects/init_db.go @@ -0,0 +1,7 @@ +package request_objects + +type InitDatabaseRequest struct { + URL string `json:"url"` + DBType string `json:"dbType"` + +}