summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus_arch2018-02-05 00:13:47 +0100
committerhorus_arch2018-02-05 00:13:47 +0100
commit543ebae42be1b7385e476a4699a7f88e95a2d120 (patch)
tree492b065baf9fe93326a1e6de36583565b386699f
parent4f7a9316da8e19fa9466ee377148c7d07bf39fd9 (diff)
downloadalkobote-543ebae42be1b7385e476a4699a7f88e95a2d120.tar.gz
Adds dependency on sqlx, viper and logrus.
-rw-r--r--config.go54
-rw-r--r--db.go8
-rw-r--r--main.go30
3 files changed, 92 insertions, 0 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..f877eba
--- /dev/null
+++ b/config.go
@@ -0,0 +1,54 @@
+package main
+
+import (
+ log "github.com/Sirupsen/logrus"
+ "github.com/spf13/viper"
+)
+
+type Config struct {
+ DBDBName string
+ DBHost string
+ DBPort int
+ DBUser string
+ DBPassword string
+ DBOptions string
+}
+
+// Parses the configuration and sets the configuration struct.
+func (c *Config) parseConfig(configFile string) {
+
+ viper.SetDefault("DBDBName", "alkobote")
+ viper.SetDefault("DBHost", "127.0.0.1")
+ viper.SetDefault("DBPort", 3306)
+
+ // Name of the configuration file
+ viper.SetConfigName("config")
+
+ // Where to find the config file
+ if configFile == "" {
+ viper.AddConfigPath("/etc/alkobote.de/")
+ viper.AddConfigPath(".")
+ viper.AddConfigPath("$HOME/.config/alkobote.de/")
+ viper.AddConfigPath("$HOME/alkobote.de/")
+ } else {
+ viper.AddConfigPath(configFile)
+ }
+
+ // Env variables need to be prefixed with "ALKOBOTE_"
+ viper.SetEnvPrefix("ALKOBOTE")
+
+ // Parses automatic the matching env variables
+ viper.AutomaticEnv()
+
+ // Reads the config
+ err := viper.ReadInConfig()
+ if err != nil {
+ log.WithFields(
+ log.Fields{
+ "error": err.Error(),
+ },
+ ).Fatal("Fatal error config file")
+ }
+
+ c.setsConfig()
+}
diff --git a/db.go b/db.go
new file mode 100644
index 0000000..f2f819d
--- /dev/null
+++ b/db.go
@@ -0,0 +1,8 @@
+package main
+
+import (
+ "github.com/jmoiron/sqlx"
+)
+
+func save_offer(W []Angebot) {
+}
diff --git a/main.go b/main.go
index ce63d37..94f1e3a 100644
--- a/main.go
+++ b/main.go
@@ -4,8 +4,19 @@ import (
"encoding/json"
"fmt"
"log"
+
+ _ "database/sql"
+ _ "github.com/go-sql-driver/mysql"
+ "github.com/jmoiron/sqlx"
)
+type App struct {
+ Offers []Angebot
+ Shops []Shop
+ Config *Config
+ DB *sqlx.DB
+}
+
type Angebot struct {
Name string
Shop string
@@ -17,8 +28,27 @@ type Angebot struct {
Valid_until string
}
+type Shop struct {
+ Name string
+ Url string
+ Logo_url string
+ Shipping_costs int
+ Free_shipping string
+}
+
func main() {
+ var err error
+
+ app := App{Config: &Config{}}
+ app.Config.parseConfig("")
+
+ // Hard coded mysql driver.
+ app.DB, err = sqlx.Connect("mysql", app.Config.DBUser+":"+app.Config.DBPassword+"@"+app.Config.DBHost+"/"+app.Config.DBDBName+app.Config.DBOptions)
+ if err != nil {
+ log.Fatal(err)
+ }
+
W := ScrapeBottleWord()
printName(W, "BottleWorld")