Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

Commit

Permalink
First import
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgoffinet committed Aug 15, 2018
0 parents commit da572ea
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vs
log
data
qflow
70 changes: 70 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright © 2018 ThreeComma.io <hello@threecomma.io>

package cmd

import (
"fmt"
"os"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/threecommaio/qflow/pkg/qflow"
)

var addr string
var config string
var dataDir string
var VERSION string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "qflow",
Long: `Replicates traffic from to various http endpoints
This tool helps replicate to multiple http endpoints backed by a
durable disk queue in the event of failures or slowdowns.`,
// Uncomment the following line if your bare application
// has an action associated with it:
Run: func(cmd *cobra.Command, args []string) {
config, err := qflow.ParseConfig(config)
if err != nil {
log.Fatal(err)
}

qflow.ListenAndServe(config, addr, dataDir)
},
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute(version string) {
VERSION = version
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().Bool("debug", false, "enable debug logging")
rootCmd.Flags().StringVarP(&addr, "addr", "a", ":8080", "listen addr")
rootCmd.Flags().StringVarP(&config, "config", "c", "", "config file for the clusters in yaml format")
rootCmd.Flags().StringVarP(&dataDir, "data-dir", "d", "", "data directory for storage")
rootCmd.MarkFlagRequired("config")
rootCmd.MarkFlagRequired("data-dir")
}

func initConfig() {
debug, _ := rootCmd.Flags().GetBool("debug")
log.SetFormatter(qflow.UTCFormatter{&log.TextFormatter{FullTimestamp: true}})

if debug {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}

viper.AutomaticEnv() // read in environment variables that match
}
8 changes: 8 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
http:
timeout: 1s

endpoints:
- name: influxdb-cke
hosts:
- http://10.211.55.6:8080
- http://10.211.55.6:8080
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright © 2018 ThreeComma.io <hello@threecomma.io>

package main

import "github.com/threecommaio/qflow/cmd"

var (
// version is set during build
version = "0.0.1"
)

func main() {
cmd.Execute(version)
}

0 comments on commit da572ea

Please sign in to comment.