Format some file using gofmt
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
1cc294872b
commit
fd835e1fcd
5 changed files with 26 additions and 26 deletions
|
@ -35,16 +35,16 @@ type Server struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Route struct {
|
type Route struct {
|
||||||
Rule string
|
Rule string
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Frontend struct {
|
type Frontend struct {
|
||||||
Backend string
|
Backend string
|
||||||
Routes map[string]Route
|
Routes map[string]Route
|
||||||
}
|
}
|
||||||
|
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
Backends map[string]Backend
|
Backends map[string]Backend
|
||||||
Frontends map[string]Frontend
|
Frontends map[string]Frontend
|
||||||
}
|
}
|
||||||
|
|
20
docker.go
20
docker.go
|
@ -2,23 +2,23 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/BurntSushi/ty/fun"
|
"github.com/BurntSushi/ty/fun"
|
||||||
|
"github.com/cenkalti/backoff"
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
"github.com/leekchan/gtf"
|
"github.com/leekchan/gtf"
|
||||||
"github.com/cenkalti/backoff"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"errors"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DockerProvider struct {
|
type DockerProvider struct {
|
||||||
Watch bool
|
Watch bool
|
||||||
Endpoint string
|
Endpoint string
|
||||||
Filename string
|
Filename string
|
||||||
Domain string
|
Domain string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDockerProvider() *DockerProvider {
|
func NewDockerProvider() *DockerProvider {
|
||||||
|
@ -45,7 +45,7 @@ var DockerFuncMap = template.FuncMap{
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for key, _ := range container.NetworkSettings.Ports {
|
for key := range container.NetworkSettings.Ports {
|
||||||
return key.Port()
|
return key.Port()
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
@ -64,7 +64,7 @@ var DockerFuncMap = template.FuncMap{
|
||||||
"getHost": getHost,
|
"getHost": getHost,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *DockerProvider) Provide(configurationChan chan <- *Configuration) {
|
func (provider *DockerProvider) Provide(configurationChan chan<- *Configuration) {
|
||||||
if dockerClient, err := docker.NewClient(provider.Endpoint); err != nil {
|
if dockerClient, err := docker.NewClient(provider.Endpoint); err != nil {
|
||||||
log.Fatalf("Failed to create a client for docker, error: %s", err)
|
log.Fatalf("Failed to create a client for docker, error: %s", err)
|
||||||
} else {
|
} else {
|
||||||
|
@ -83,9 +83,9 @@ func (provider *DockerProvider) Provide(configurationChan chan <- *Configuration
|
||||||
event := <-dockerEvents
|
event := <-dockerEvents
|
||||||
if event == nil {
|
if event == nil {
|
||||||
return errors.New("Docker event nil")
|
return errors.New("Docker event nil")
|
||||||
// log.Fatalf("Docker connection error")
|
// log.Fatalf("Docker connection error")
|
||||||
}
|
}
|
||||||
if (event.Status == "start" || event.Status == "die" ) {
|
if event.Status == "start" || event.Status == "die" {
|
||||||
log.Debug("Docker event receveived %+v", event)
|
log.Debug("Docker event receveived %+v", event)
|
||||||
configuration := provider.loadDockerConfig(dockerClient)
|
configuration := provider.loadDockerConfig(dockerClient)
|
||||||
if configuration != nil {
|
if configuration != nil {
|
||||||
|
|
|
@ -4,10 +4,10 @@ Copyright
|
||||||
package middlewares
|
package middlewares
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/handlers"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"github.com/gorilla/handlers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Logger is a middleware handler that logs the request as it goes in and the response as it goes out.
|
// Logger is a middleware handler that logs the request as it goes in and the response as it goes out.
|
||||||
|
@ -17,21 +17,21 @@ type Logger struct {
|
||||||
|
|
||||||
// NewLogger returns a new Logger instance
|
// NewLogger returns a new Logger instance
|
||||||
func NewLogger(file string) *Logger {
|
func NewLogger(file string) *Logger {
|
||||||
if (len(file) > 0 ) {
|
if len(file) > 0 {
|
||||||
fi, err := os.OpenFile(file, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
|
fi, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error opening file", err)
|
log.Fatal("Error opening file", err)
|
||||||
}
|
}
|
||||||
return &Logger{fi}
|
return &Logger{fi}
|
||||||
}else {
|
} else {
|
||||||
return &Logger{nil}
|
return &Logger{nil}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||||
if (l.file == nil) {
|
if l.file == nil {
|
||||||
next(rw, r)
|
next(rw, r)
|
||||||
}else {
|
} else {
|
||||||
handlers.CombinedLoggingHandler(l.file, next).ServeHTTP(rw, r)
|
handlers.CombinedLoggingHandler(l.file, next).ServeHTTP(rw, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@ Copyright
|
||||||
package middlewares
|
package middlewares
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"encoding/json"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Routes struct {
|
type Routes struct {
|
||||||
|
@ -19,8 +19,8 @@ func NewRoutes(router *mux.Router) *Routes {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (router *Routes) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
func (router *Routes) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||||
routeMatch :=mux.RouteMatch{}
|
routeMatch := mux.RouteMatch{}
|
||||||
if(router.router.Match(r, &routeMatch)){
|
if router.router.Match(r, &routeMatch) {
|
||||||
json, _ := json.Marshal(routeMatch.Handler)
|
json, _ := json.Marshal(routeMatch.Handler)
|
||||||
log.Println("Request match route ", json)
|
log.Println("Request match route ", json)
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,7 +215,7 @@ func LoadConfig(configuration *Configuration, gloablConfiguration *GlobalConfigu
|
||||||
|
|
||||||
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 {
|
||||||
inputs[i] = reflect.ValueOf(args[i])
|
inputs[i] = reflect.ValueOf(args[i])
|
||||||
}
|
}
|
||||||
return reflect.ValueOf(any).MethodByName(name).Call(inputs)
|
return reflect.ValueOf(any).MethodByName(name).Call(inputs)
|
||||||
|
|
Loading…
Reference in a new issue