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

Fix some linter issues #26

Open
wants to merge 3 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
13 changes: 7 additions & 6 deletions conf/configuration.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package conf

import (
"github.com/opsgenie/oec/git"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"os"
"path/filepath"
"strings"
"time"

"github.com/opsgenie/oec/git"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -101,9 +102,9 @@ func ReadConfFile() (*Configuration, error) {
if err != nil {
return nil, err
}

if os.Getenv("OEC_API_KEY") != "" {
conf.ApiKey = os.Getenv("OEC_API_KEY")
conf.ApiKey = os.Getenv("OEC_API_KEY")
}

err = validateConfiguration(conf)
Expand Down Expand Up @@ -194,7 +195,7 @@ func readConfFileFromSource(confSourceType string) (*Configuration, error) {
case LocalSourceType:
confFilepath := os.Getenv("OEC_CONF_LOCAL_FILEPATH")

if len(confFilepath) <= 0 {
if len(confFilepath) == 0 {
confFilepath = addHomeDirPrefix(defaultConfFilepath)
} else {
confFilepath = addHomeDirPrefix(confFilepath)
Expand Down
15 changes: 8 additions & 7 deletions conf/configuration_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package conf

import (
"os"
"testing"

"github.com/opsgenie/oec/git"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"os"
"testing"
)

var readConfigurationFromGitCalled = false
Expand Down Expand Up @@ -46,7 +47,7 @@ func expectedConf() *Configuration {
"-apiKey", expectedConf.ApiKey,
"-opsgenieUrl", expectedConf.BaseUrl,
"-logLevel", "INFO"},
expectedConf.GlobalArgs...
expectedConf.GlobalArgs...,
)

if expectedConf.LogrusLevel == 0 {
Expand Down Expand Up @@ -107,19 +108,19 @@ const testLocalConfFilePath = "/path/to/test/conf/file.json"
func mockReadConfigurationFromGit(owner, repo, filepath, token string) (*Configuration, error) {
readConfigurationFromGitCalled = true

if len(owner) <= 0 {
if len(owner) == 0 {
return nil, errors.New("Owner was empty.")
}

if len(repo) <= 0 {
if len(repo) == 0 {
return nil, errors.New("Repo was empty.")
}

if len(filepath) <= 0 {
if len(filepath) == 0 {
return nil, errors.New("Filepath was empty.")
}

if len(token) <= 0 {
if len(token) == 0 {
return nil, errors.New("Token was empty.")
}

Expand Down
3 changes: 2 additions & 1 deletion conf/from_git.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package conf

import (
"github.com/opsgenie/oec/git"
"os"
"path/filepath"

"github.com/opsgenie/oec/git"
)

var cloneMasterFunc = git.CloneMaster
Expand Down
3 changes: 2 additions & 1 deletion conf/from_git_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package conf

import (
"testing"

"github.com/opsgenie/oec/git"
"github.com/opsgenie/oec/util"
"github.com/stretchr/testify/assert"
"testing"
)

func TestReadConfigurationFromGit(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions conf/from_local_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package conf

import (
"github.com/opsgenie/oec/util"
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/opsgenie/oec/util"
"github.com/stretchr/testify/assert"
)

func TestReadConfigurationFromLocal(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions conf/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package conf

import (
"encoding/json"
"github.com/opsgenie/oec/git"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
fpath "path/filepath"
"runtime"
"strings"
"time"

"github.com/opsgenie/oec/git"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)

const unknownFileExtErrMessage = "Unknown configuration file extension[%s]. Only \".json\" and \".yml(.yaml)\" types are allowed."
Expand Down
5 changes: 3 additions & 2 deletions conf/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package conf

import (
"fmt"
"github.com/opsgenie/oec/util"
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/opsgenie/oec/util"
"github.com/stretchr/testify/assert"
)

func TestReadConfigurationFromJsonFile(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions git/clone.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package git

import (
"io/ioutil"
"os"

"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
"io/ioutil"
"os"
)

var gitCloneMasterFunc = gitCloneMaster
Expand Down
5 changes: 3 additions & 2 deletions git/repository.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package git

import (
"os"
"sync"

"github.com/opsgenie/oec/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/src-d/go-git.v4"
"os"
"sync"
)

type GitOptions struct {
Expand Down
26 changes: 12 additions & 14 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ package main
import (
"flag"
"fmt"
"github.com/opsgenie/oec/conf"
"github.com/opsgenie/oec/queue"
"github.com/opsgenie/oec/util"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
"io"
"net/http"
"os"
Expand All @@ -18,6 +12,13 @@ import (
"strconv"
"syscall"
"time"

"github.com/opsgenie/oec/conf"
"github.com/opsgenie/oec/queue"
"github.com/opsgenie/oec/util"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
)

var metricAddr = flag.String("oec-metrics", "7070", "The address to listen on for HTTP requests.")
Expand Down Expand Up @@ -79,14 +80,11 @@ func main() {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)

select {
case <-signals:
logrus.Infof("OEC will be stopped gracefully.")
err := queueProcessor.StopProcessing()
if err != nil {
logrus.Fatalln(err)
}
<-signals
logrus.Infof("OEC will be stopped gracefully.")
err = queueProcessor.StopProcessing()
if err != nil {
logrus.Fatalln(err)
}

os.Exit(0)
}
5 changes: 3 additions & 2 deletions queue/job.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package queue

import (
"sync"
"time"

"github.com/aws/aws-sdk-go/service/sqs"
"github.com/opsgenie/oec/runbook"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"sync"
"time"
)

const (
Expand Down
9 changes: 5 additions & 4 deletions queue/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package queue

import (
"encoding/json"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/opsgenie/oec/runbook"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"net/http/httptest"
"sync"
"testing"

"github.com/aws/aws-sdk-go/service/sqs"
"github.com/opsgenie/oec/runbook"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

var mockActionResultPayload = &runbook.ActionResultPayload{Action: "MockAction"}
Expand Down
13 changes: 7 additions & 6 deletions queue/poller.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package queue

import (
"io"
"os"
"path/filepath"
"strconv"
"sync"
"time"

"github.com/aws/aws-sdk-go/service/sqs"
"github.com/opsgenie/oec/conf"
"github.com/opsgenie/oec/git"
"github.com/opsgenie/oec/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
"io"
"os"
"path/filepath"
"strconv"
"sync"
"time"
)

type Poller interface {
Expand Down
7 changes: 4 additions & 3 deletions queue/poller_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package queue

import (
"io"
"sync"
"testing"

"github.com/aws/aws-sdk-go/service/sqs"
"github.com/opsgenie/oec/conf"
"github.com/opsgenie/oec/git"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"io"
"sync"
"testing"
)

var mockPollerConf = &conf.PollerConf{
Expand Down
5 changes: 3 additions & 2 deletions queue/queue_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package queue
import (
"encoding/json"
"fmt"
"io"
"time"

"github.com/aws/aws-sdk-go/service/sqs"
"github.com/opsgenie/oec/conf"
"github.com/opsgenie/oec/git"
"github.com/opsgenie/oec/runbook"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"io"
"time"
)

type QueueMessage interface {
Expand Down
9 changes: 5 additions & 4 deletions queue/queue_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package queue

import (
"bytes"
"io"
"math/rand"
"testing"
"time"

"github.com/aws/aws-sdk-go/service/sqs"
"github.com/opsgenie/oec/conf"
"github.com/opsgenie/oec/git"
"github.com/opsgenie/oec/runbook"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"io"
"math/rand"
"testing"
"time"
)

var (
Expand Down
13 changes: 7 additions & 6 deletions queue/queue_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package queue
import (
"bytes"
"encoding/json"
"github.com/opsgenie/oec/conf"
"github.com/opsgenie/oec/git"
"github.com/opsgenie/oec/retryer"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
"io"
"io/ioutil"
"net/http"
"strconv"
"sync"
"time"

"github.com/opsgenie/oec/conf"
"github.com/opsgenie/oec/git"
"github.com/opsgenie/oec/retryer"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
)

var UserAgentHeader string
Expand Down
Loading