Skip to content

Commit

Permalink
Update URL parsing for go 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
glinton committed Feb 21, 2017
1 parent 43610a0 commit bb6a7a2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
9 changes: 5 additions & 4 deletions authenticator/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ var (

// Init initializes the chosen authenticator
func Init() error {
var err error
var u *url.URL
u, err = url.Parse(config.AuthAddress)
u, err := url.Parse(config.AuthAddress)
if err != nil {
return fmt.Errorf("Failed to parse db connection - %s", err)
u, err = url.Parse("boltdb://" + config.AuthAddress)
if err != nil {
return fmt.Errorf("Failed to parse auth connection - %s", err)
}
}
switch u.Scheme {
case "boltdb":
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
Insecure = false // whether or not to start insecure
Server = false // whether or not to start logvac as a server
Version = false // whether or not to print version info and exit
CleanFreq = 60 // how often to clean log database
)

// AddFlags adds cli flags to logvac
Expand All @@ -60,6 +61,8 @@ func AddFlags(cmd *cobra.Command) {
cmd.Flags().BoolVarP(&Server, "server", "s", Server, "Run as server")
cmd.Flags().BoolVarP(&Insecure, "insecure", "i", Insecure, "Don't use TLS (used for testing)")
cmd.Flags().BoolVarP(&Version, "version", "v", Version, "Print version info and exit")
cmd.Flags().IntVar(&CleanFreq, "clean-frequency", CleanFreq, "How often to clean log database")
cmd.Flags().MarkHidden("clean-frequency")

Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))
}
Expand Down
15 changes: 7 additions & 8 deletions drain/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import (
"github.com/nanopack/logvac/core"
)

var (
// How often to clean, exported for testing
CleanFreq = 60
)

type (
// BoltArchive is a boltDB archiver
BoltArchive struct {
Expand Down Expand Up @@ -180,12 +175,16 @@ func (a BoltArchive) Expire() {
var logKeep map[string]interface{}
err := json.Unmarshal([]byte(config.LogKeep), &logKeep)
if err != nil {
config.Log.Fatal("Bad JSON syntax for log-keep - %s", err)
os.Exit(1) // maybe not?
config.Log.Fatal("Bad JSON syntax for log-keep - %s, saving logs indefinitely", err)
return
}

if config.CleanFreq < 1 {
config.CleanFreq = 60
}

// clean up every minute // todo: maybe 5mins?
tick := time.Tick(time.Duration(CleanFreq) * time.Second)
tick := time.Tick(time.Duration(config.CleanFreq) * time.Second)
for {
select {
case <-tick:
Expand Down
2 changes: 1 addition & 1 deletion drain/boltdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestExpire(t *testing.T) {
// manually configure and start internals
func initialize() error {
var err error
drain.CleanFreq = 1
config.CleanFreq = 1
config.LogKeep = `{"app": "1s", "deploy":0}`
config.LogKeep = `{"app": "1s", "deploy":0, "a":"1m", "aa":"1h", "b":"1d", "c":"1w", "d":"1y", "e":"1"}`
config.Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))
Expand Down
10 changes: 8 additions & 2 deletions drain/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func Init() error {
func archiveInit() error {
u, err := url.Parse(config.DbAddress)
if err != nil {
return fmt.Errorf("Failed to parse db connection - %s", err)
u, err = url.Parse("boltdb://" + config.DbAddress)
if err != nil {
return fmt.Errorf("Failed to parse db connection - %s", err)
}
}
switch u.Scheme {
case "boltdb":
Expand Down Expand Up @@ -98,7 +101,10 @@ func archiveInit() error {
func publishInit() error {
u, err := url.Parse(config.PubAddress)
if err != nil {
return fmt.Errorf("Failed to parse publisher connection - %s", err)
u, err = url.Parse("mist://" + config.PubAddress) // hard requirement for scheme in go 1.8 (with ip:port only)
if err != nil {
return fmt.Errorf("Failed to parse publisher connection - %s", err)
}
}
switch u.Scheme {
case "mist":
Expand Down
2 changes: 1 addition & 1 deletion drain/mist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestPublish(t *testing.T) {
// manually configure and start internals
func mistInitialize() error {
var err error
drain.CleanFreq = 1
config.CleanFreq = 1
config.LogKeep = `{"app": "1s", "deploy":0}`
config.LogKeep = `{"app": "1s", "deploy":0, "a":"1m", "aa":"1h", "b":"1d", "c":"1w", "d":"1y", "e":"1"}`
config.Log = lumber.NewConsoleLogger(lumber.LvlInt("ERROR"))
Expand Down

0 comments on commit bb6a7a2

Please sign in to comment.