Add validate-golint target and script …
… and *lint* the latest piece of code. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
7607eb173b
commit
40391c57c2
8 changed files with 78 additions and 33 deletions
5
Makefile
5
Makefile
|
@ -40,7 +40,7 @@ test-integration: build
|
||||||
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate test-integration
|
$(DOCKER_RUN_TRAEFIK) ./script/make.sh generate test-integration
|
||||||
|
|
||||||
validate: build
|
validate: build
|
||||||
$(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-gofmt validate-govet
|
$(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-gofmt validate-govet validate-golint
|
||||||
|
|
||||||
validate-gofmt: build
|
validate-gofmt: build
|
||||||
$(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-gofmt
|
$(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-gofmt
|
||||||
|
@ -48,6 +48,9 @@ validate-gofmt: build
|
||||||
validate-govet: build
|
validate-govet: build
|
||||||
$(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-govet
|
$(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-govet
|
||||||
|
|
||||||
|
validate-golint: build
|
||||||
|
$(DOCKER_RUN_TRAEFIK) ./script/make.sh validate-golint
|
||||||
|
|
||||||
build: dist
|
build: dist
|
||||||
docker build -t "$(TRAEFIK_DEV_IMAGE)" -f build.Dockerfile .
|
docker build -t "$(TRAEFIK_DEV_IMAGE)" -f build.Dockerfile .
|
||||||
|
|
||||||
|
|
17
adapters.go
17
adapters.go
|
@ -4,40 +4,37 @@ Copyright
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/mailgun/oxy/utils"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// OxyLogger implements oxy Logger interface with logrus.
|
||||||
type OxyLogger struct {
|
type OxyLogger struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Infof logs specified string as Debug level in logrus.
|
||||||
func (oxylogger *OxyLogger) Infof(format string, args ...interface{}) {
|
func (oxylogger *OxyLogger) Infof(format string, args ...interface{}) {
|
||||||
log.Debugf(format, args...)
|
log.Debugf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Warningf logs specified string as Warning level in logrus.
|
||||||
func (oxylogger *OxyLogger) Warningf(format string, args ...interface{}) {
|
func (oxylogger *OxyLogger) Warningf(format string, args ...interface{}) {
|
||||||
log.Warningf(format, args...)
|
log.Warningf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Errorf logs specified string as Error level in logrus.
|
||||||
func (oxylogger *OxyLogger) Errorf(format string, args ...interface{}) {
|
func (oxylogger *OxyLogger) Errorf(format string, args ...interface{}) {
|
||||||
log.Errorf(format, args...)
|
log.Errorf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrorHandler struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *ErrorHandler) ServeHTTP(w http.ResponseWriter, req *http.Request, err error) {
|
|
||||||
log.Error("server error ", err.Error())
|
|
||||||
utils.DefaultHandler.ServeHTTP(w, req, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
|
func notFoundHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
//templatesRenderer.HTML(w, http.StatusNotFound, "notFound", nil)
|
//templatesRenderer.HTML(w, http.StatusNotFound, "notFound", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadDefaultConfig returns a default gorrilla.mux router from the specified configuration.
|
||||||
func LoadDefaultConfig(globalConfiguration *GlobalConfiguration) *mux.Router {
|
func LoadDefaultConfig(globalConfiguration *GlobalConfiguration) *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.NotFoundHandler = http.HandlerFunc(notFoundHandler)
|
router.NotFoundHandler = http.HandlerFunc(notFoundHandler)
|
||||||
|
|
|
@ -4,6 +4,7 @@ RUN go get github.com/Masterminds/glide
|
||||||
RUN go get github.com/mitchellh/gox
|
RUN go get github.com/mitchellh/gox
|
||||||
RUN go get github.com/tcnksm/ghr
|
RUN go get github.com/tcnksm/ghr
|
||||||
RUN go get github.com/jteeuwen/go-bindata/...
|
RUN go get github.com/jteeuwen/go-bindata/...
|
||||||
|
RUN go get github.com/golang/lint/golint
|
||||||
|
|
||||||
# Which docker version to test on
|
# Which docker version to test on
|
||||||
ENV DOCKER_VERSION 1.6.2
|
ENV DOCKER_VERSION 1.6.2
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
fmtlog "log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/emilevauge/traefik/provider"
|
"github.com/emilevauge/traefik/provider"
|
||||||
"github.com/emilevauge/traefik/types"
|
"github.com/emilevauge/traefik/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GlobalConfiguration holds global configuration (with providers, etc.).
|
||||||
|
// It's populated from the traefik configuration file passed as an argument to the binary.
|
||||||
type GlobalConfiguration struct {
|
type GlobalConfiguration struct {
|
||||||
Port string
|
Port string
|
||||||
GraceTimeOut int64
|
GraceTimeOut int64
|
||||||
|
@ -25,6 +29,7 @@ type GlobalConfiguration struct {
|
||||||
Boltdb *provider.BoltDb
|
Boltdb *provider.BoltDb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewGlobalConfiguration returns a GlobalConfiguration with default values.
|
||||||
func NewGlobalConfiguration() *GlobalConfiguration {
|
func NewGlobalConfiguration() *GlobalConfiguration {
|
||||||
globalConfiguration := new(GlobalConfiguration)
|
globalConfiguration := new(GlobalConfiguration)
|
||||||
// default values
|
// default values
|
||||||
|
@ -36,4 +41,13 @@ func NewGlobalConfiguration() *GlobalConfiguration {
|
||||||
return globalConfiguration
|
return globalConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadFileConfig returns a GlobalConfiguration from reading the specified file (a toml file).
|
||||||
|
func LoadFileConfig(file string) *GlobalConfiguration {
|
||||||
|
configuration := NewGlobalConfiguration()
|
||||||
|
if _, err := toml.DecodeFile(file, configuration); err != nil {
|
||||||
|
fmtlog.Fatalf("Error reading file: %s", err)
|
||||||
|
}
|
||||||
|
return configuration
|
||||||
|
}
|
||||||
|
|
||||||
type configs map[string]*types.Configuration
|
type configs map[string]*types.Configuration
|
||||||
|
|
31
script/validate-golint
Executable file
31
script/validate-golint
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
source "$(dirname "$BASH_SOURCE")/.validate"
|
||||||
|
|
||||||
|
IFS=$'\n'
|
||||||
|
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/\|autogen' || true) )
|
||||||
|
unset IFS
|
||||||
|
|
||||||
|
errors=()
|
||||||
|
for f in "${files[@]}"; do
|
||||||
|
# we use "git show" here to validate that what's committed passes go vet
|
||||||
|
failedLint=$(golint "$f")
|
||||||
|
if [ "$failedLint" ]; then
|
||||||
|
errors+=( "$failedLint" )
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ${#errors[@]} -eq 0 ]; then
|
||||||
|
echo 'Congratulations! All Go source files have been linted.'
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "Errors from golint:"
|
||||||
|
for err in "${errors[@]}"; do
|
||||||
|
echo "$err"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
echo 'Please fix the above errors. You can test via "golint" and commit the result.'
|
||||||
|
echo
|
||||||
|
} >&2
|
||||||
|
false
|
||||||
|
fi
|
21
traefik.go
21
traefik.go
|
@ -14,7 +14,6 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/codegangsta/negroni"
|
"github.com/codegangsta/negroni"
|
||||||
"github.com/emilevauge/traefik/middlewares"
|
"github.com/emilevauge/traefik/middlewares"
|
||||||
|
@ -266,7 +265,7 @@ func prepareServer(router *mux.Router, globalConfiguration *GlobalConfiguration,
|
||||||
Handler: negroni,
|
Handler: negroni,
|
||||||
TLSConfig: tlsConfig,
|
TLSConfig: tlsConfig,
|
||||||
}), nil
|
}), nil
|
||||||
} else {
|
}
|
||||||
server, err := oldServer.HijackListener(&http.Server{
|
server, err := oldServer.HijackListener(&http.Server{
|
||||||
Addr: globalConfiguration.Port,
|
Addr: globalConfiguration.Port,
|
||||||
Handler: negroni,
|
Handler: negroni,
|
||||||
|
@ -274,12 +273,12 @@ func prepareServer(router *mux.Router, globalConfiguration *GlobalConfiguration,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error hijacking server %s", err)
|
log.Fatalf("Error hijacking server %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
}
|
||||||
return server, nil
|
return server, nil
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadConfig returns a new gorrilla.mux Route from the specified global configuration and the dynamic
|
||||||
|
// provider configurations.
|
||||||
func LoadConfig(configurations configs, globalConfiguration *GlobalConfiguration) (*mux.Router, error) {
|
func LoadConfig(configurations configs, globalConfiguration *GlobalConfiguration) (*mux.Router, error) {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.NotFoundHandler = http.HandlerFunc(notFoundHandler)
|
router.NotFoundHandler = http.HandlerFunc(notFoundHandler)
|
||||||
|
@ -346,13 +345,15 @@ func LoadConfig(configurations configs, globalConfiguration *GlobalConfiguration
|
||||||
newRoute.Handler(backends[frontend.Backend])
|
newRoute.Handler(backends[frontend.Backend])
|
||||||
err := newRoute.GetError()
|
err := newRoute.GetError()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error building route: %s", err)
|
log.Errorf("Error building route: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return router, nil
|
return router, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invoke calls the specified method with the specified arguments on the specified interface.
|
||||||
|
// It uses the go(lang) reflect package.
|
||||||
func Invoke(any interface{}, name string, args ...interface{}) []reflect.Value {
|
func Invoke(any interface{}, name string, args ...interface{}) []reflect.Value {
|
||||||
inputs := make([]reflect.Value, len(args))
|
inputs := make([]reflect.Value, len(args))
|
||||||
for i := range args {
|
for i := range args {
|
||||||
|
@ -360,11 +361,3 @@ func Invoke(any interface{}, name string, args ...interface{}) []reflect.Value {
|
||||||
}
|
}
|
||||||
return reflect.ValueOf(any).MethodByName(name).Call(inputs)
|
return reflect.ValueOf(any).MethodByName(name).Call(inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadFileConfig(file string) *GlobalConfiguration {
|
|
||||||
configuration := NewGlobalConfiguration()
|
|
||||||
if _, err := toml.DecodeFile(file, configuration); err != nil {
|
|
||||||
fmtlog.Fatalf("Error reading file: %s", err)
|
|
||||||
}
|
|
||||||
return configuration
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Version holds the current version of traefik.
|
||||||
Version = ""
|
Version = ""
|
||||||
|
// BuildDate holds the build date of traefik.
|
||||||
BuildDate = ""
|
BuildDate = ""
|
||||||
)
|
)
|
||||||
|
|
4
web.go
4
web.go
|
@ -14,6 +14,8 @@ import (
|
||||||
"github.com/unrolled/render"
|
"github.com/unrolled/render"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WebProvider is a provider.Provider implementation that provides the UI.
|
||||||
|
// FIXME to be handled another way.
|
||||||
type WebProvider struct {
|
type WebProvider struct {
|
||||||
Address string
|
Address string
|
||||||
CertFile, KeyFile string
|
CertFile, KeyFile string
|
||||||
|
@ -25,6 +27,8 @@ var (
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Provide allows the provider to provide configurations to traefik
|
||||||
|
// using the given configuration channel.
|
||||||
func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessage) error {
|
func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessage) error {
|
||||||
systemRouter := mux.NewRouter()
|
systemRouter := mux.NewRouter()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue