Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch over to master #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
vendor/*

cache/*
Expand Down
6 changes: 3 additions & 3 deletions command/fetch.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package command

import (
"github.com/pawski/go-xchange/procctl"
"github.com/pawski/go-xchange/configuration"
"time"
"github.com/pawski/go-xchange/logger"
"github.com/pawski/go-xchange/http"
"github.com/pawski/go-xchange/logger"
"github.com/pawski/go-xchange/procctl"
"github.com/pawski/go-xchange/rabbitmq"
"time"
)

func FetchExecute() (err error) {
Expand Down
24 changes: 12 additions & 12 deletions configuration/main.go → configuration/config.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
package configuration

import (
"github.com/pawski/go-xchange/logger"
"gopkg.in/yaml.v2"
"io/ioutil"
"github.com/pawski/go-xchange/logger"
"sync"
)

type config struct {
InfluxDbHost string `yaml:"influx_host"`
InfluxDbDatabase string `yaml:"influx_database"`
RabbitMqUrl string `yaml:"rabbitmq_url"`
WalutomatUrl string `yaml:"walutomat_url"`
CollectUpdateInterval int64 `yaml:"collect_update_interval"`
type Config struct {
InfluxDbHost string `yaml:"influx_host"`
InfluxDbDatabase string `yaml:"influx_database"`
RabbitMqUrl string `yaml:"rabbitmq_url"`
WalutomatUrl string `yaml:"walutomat_url"`
CollectUpdateInterval int64 `yaml:"collect_update_interval"`
}

var cfg config
var cfg Config
var once sync.Once

func Get() (config) {
func Get() Config {
once.Do(func() {
cfg = loadConfiguration()
})

return cfg
}

func loadConfiguration() (config) {
func loadConfiguration() Config {
source, err := ioutil.ReadFile("config.yml")

if err != nil {
logger.Get().Fatalf("error: %v", err)
}

var config config
var config Config

err = yaml.Unmarshal([]byte(source), &config)

Expand All @@ -42,4 +42,4 @@ func loadConfiguration() (config) {
}

return config
}
}
27 changes: 0 additions & 27 deletions glide.lock

This file was deleted.

15 changes: 0 additions & 15 deletions glide.yaml

This file was deleted.

21 changes: 21 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module github.com/pawski/go-xchange

go 1.17

require (
github.com/Sirupsen/logrus v1.0.3
github.com/influxdata/influxdb v1.4.2
github.com/streadway/amqp v0.0.0-20171101222333-ff791c2d22d3
github.com/urfave/cli v1.20.0
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7
)

require (
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/stretchr/testify v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20170825220121-81e90905daef // indirect
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
)
39 changes: 39 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
github.com/Sirupsen/logrus v1.0.3 h1:XbmgH2T0Ow2lAHu3IwQTqtwD2NgFdIj5notkpw3BpUM=
github.com/Sirupsen/logrus v1.0.3/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/influxdata/influxdb v1.4.2 h1:pq6sesLixc1JKoF0P+n3DgijC0UlWi6ZQh01o3qu2f0=
github.com/influxdata/influxdb v1.4.2/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/streadway/amqp v0.0.0-20171101222333-ff791c2d22d3 h1:qIyhhqB8VkGrFFxoFk3fWJavm55YQNFrf2qKr4cO7r4=
github.com/streadway/amqp v0.0.0-20171101222333-ff791c2d22d3/go.mod h1:1WNBiOZtZQLpVAyu0iTduoJL9hEsMloAK5XWrtW0xdY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
golang.org/x/crypto v0.0.0-20170825220121-81e90905daef h1:R8ubLIilYRXIXpgjOg2l/ECVs3HzVKIjJEhxSsQ91u4=
golang.org/x/crypto v0.0.0-20170825220121-81e90905daef/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNjB2u4i700xBkIT4e0=
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7 h1:+t9dhfO+GNOIGJof6kPOAenx7YgrZMTdRPV+EsnPabk=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6 changes: 3 additions & 3 deletions influxdb/client.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package influxdb

import (
"github.com/influxdata/influxdb/client/v2"
"github.com/pawski/go-xchange/configuration"
"github.com/pawski/go-xchange/logger"
"github.com/influxdata/influxdb/client/v2"
"sync"
)

var dbClient client.Client
var once sync.Once

func Get() (client.Client) {
once.Do(func(){
func Get() client.Client {
once.Do(func() {
// Create a new HTTPClient
var err error
dbClient, err = client.NewHTTPClient(client.HTTPConfig{
Expand Down
2 changes: 1 addition & 1 deletion logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ func Get() *logrus.Logger {

func SetDebugLevel() {
Get().Level = logrus.DebugLevel
}
}
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package main

import (
"github.com/Sirupsen/logrus"
"os"
"github.com/urfave/cli"
"github.com/pawski/go-xchange/command"
"github.com/pawski/go-xchange/logger"
"github.com/urfave/cli"
"os"
)

func main() {

app := cli.NewApp()
app.Name = "XChange"
app.Version = "v0.1"
Expand Down Expand Up @@ -44,7 +43,7 @@ func main() {
logger.Get().Error(err)
}
},
},{
}, {
Name: "fetch",
Usage: "Fetch currency rates",
Action: func(c *cli.Context) {
Expand Down
35 changes: 17 additions & 18 deletions rabbitmq/client.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package rabbitmq

import (
"sync"
"github.com/pawski/go-xchange/configuration"
"github.com/pawski/go-xchange/logger"
"github.com/streadway/amqp"
"github.com/pawski/go-xchange/configuration"
"sync"
)

var connection = amqp.Connection{}
var once sync.Once

func Connect() (amqp.Connection) {
func Connect() amqp.Connection {
once.Do(func() {
conn, err := amqp.Dial(configuration.Get().RabbitMqUrl)
failOnError(err, "Failed to connect to RabbitMQ")
Expand All @@ -21,7 +21,7 @@ func Connect() (amqp.Connection) {
return connection
}

func ConsumeFromQueue(consume func(<-chan amqp.Delivery)) () {
func ConsumeFromQueue(consume func(<-chan amqp.Delivery)) {
Connect()

channel, err := connection.Channel()
Expand All @@ -30,11 +30,11 @@ func ConsumeFromQueue(consume func(<-chan amqp.Delivery)) () {

q, err := channel.QueueDeclare(
"rates_queue", // name
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
failOnError(err, "Failed to declare a queue")

Expand All @@ -48,7 +48,7 @@ func ConsumeFromQueue(consume func(<-chan amqp.Delivery)) () {
messages, err := channel.Consume(
q.Name, // queue
"", // consumer
false, // auto-ack
false, // auto-ack
false, // exclusive
false, // no-local
false, // no-wait
Expand All @@ -59,8 +59,7 @@ func ConsumeFromQueue(consume func(<-chan amqp.Delivery)) () {
consume(messages)
}


func PublishToQueue(message []byte) {
func PublishToQueue(message []byte) {

Connect()

Expand All @@ -70,11 +69,11 @@ func PublishToQueue(message []byte) {

q, err := channel.QueueDeclare(
"rates_queue", // name
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
failOnError(err, "Failed to declare a queue")

Expand All @@ -88,7 +87,7 @@ func PublishToQueue(message []byte) {
ContentType: "text/plain",
Body: []byte(body),
})
logger.Get().Infof(" [x] Sent %s",message)
logger.Get().Infof(" [x] Sent %s", message)
failOnError(err, "Failed to publish a message")
}

Expand Down
12 changes: 6 additions & 6 deletions walutomat/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func offerResponseToOffer(offerResponse OffersResponse) ([] Offer) {
for _, offerResponse := range offerResponse.Offers {
offers = append(offers, Offer{
Pair: offerResponse.Pair,
Buy: stringToFloat(offerResponse.Buy.String()),
BuyOld: stringToFloat(offerResponse.BuyOld.String()),
Sell: stringToFloat(offerResponse.Sell.String()),
SellOld: stringToFloat(offerResponse.SellOld.String()),
Buy: offerResponse.Buy,
BuyOld: offerResponse.BuyOld,
Sell: offerResponse.Sell,
SellOld: offerResponse.SellOld,
CountBuy: offerResponse.CountBuy,
CountSell: offerResponse.CountSell,
Avg: stringToFloat(offerResponse.Avg.String()),
AvgOld: stringToFloat(offerResponse.AvgOld.String()),
Avg: offerResponse.Avg,
AvgOld: offerResponse.AvgOld,
})
}

Expand Down
14 changes: 6 additions & 8 deletions walutomat/offerResponse.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package walutomat

import "encoding/json"

type OffersResponse struct {
Offers []struct {
Buy json.Number `json:"buy"`
Sell json.Number `json:"sell"`
BuyOld json.Number `json:"buy_old"`
SellOld json.Number `json:"sell_old"`
Buy float32 `json:"buy"`
Sell float32 `json:"sell"`
BuyOld float32 `json:"buy_old"`
SellOld float32 `json:"sell_old"`
CountSell int `json:"count_sell"`
CountBuy int `json:"count_buy"`
Pair string `json:"pair"`
Avg json.Number `json:"avg"`
AvgOld json.Number `json:"avg_old"`
Avg float32 `json:"avg"`
AvgOld float32 `json:"avg_old"`
} `json:"offers"`
}