dangogh closed pull request #2001: move config.go into config package so it can
be used in other packages
URL: https://github.com/apache/incubator-trafficcontrol/pull/2001
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/traffic_ops/traffic_ops_golang/config.go
b/traffic_ops/traffic_ops_golang/config/config.go
similarity index 99%
rename from traffic_ops/traffic_ops_golang/config.go
rename to traffic_ops/traffic_ops_golang/config/config.go
index 0d58dabb7..1a5ebdd0c 100644
--- a/traffic_ops/traffic_ops_golang/config.go
+++ b/traffic_ops/traffic_ops_golang/config/config.go
@@ -1,4 +1,4 @@
-package main
+package config
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/traffic_ops/traffic_ops_golang/config_test.go
b/traffic_ops/traffic_ops_golang/config/config_test.go
similarity index 99%
rename from traffic_ops/traffic_ops_golang/config_test.go
rename to traffic_ops/traffic_ops_golang/config/config_test.go
index 366d7fe21..7e7ef8fef 100644
--- a/traffic_ops/traffic_ops_golang/config_test.go
+++ b/traffic_ops/traffic_ops_golang/config/config_test.go
@@ -1,4 +1,4 @@
-package main
+package config
/*
* Licensed to the Apache Software Foundation (ASF) under one
diff --git a/traffic_ops/traffic_ops_golang/deliveryservices_keys.go
b/traffic_ops/traffic_ops_golang/deliveryservices_keys.go
index 11a6de02b..dadf6948a 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservices_keys.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservices_keys.go
@@ -35,6 +35,7 @@ import (
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
+
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/config"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/riaksvc"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/tenant"
"github.com/basho/riak-go-client"
@@ -99,7 +100,7 @@ func getXMLID(cdnID sql.NullInt64, hostRegex string, db
*sqlx.DB) (sql.NullStrin
return xmlID, nil
}
-func getDeliveryServiceSSLKeysByXMLID(xmlID string, version string, db
*sqlx.DB, cfg Config) ([]byte, error) {
+func getDeliveryServiceSSLKeysByXMLID(xmlID string, version string, db
*sqlx.DB, cfg config.Config) ([]byte, error) {
var respBytes []byte
// create and start a cluster
cluster, err := riaksvc.GetRiakCluster(db, cfg.RiakAuthOptions)
@@ -241,7 +242,7 @@ func verifyAndEncodeCertificate(certificate string, rootCA
string) (string, erro
return base64EncodedStr, nil
}
-func addDeliveryServiceSSLKeysHandler(db *sqlx.DB, cfg Config)
http.HandlerFunc {
+func addDeliveryServiceSSLKeysHandler(db *sqlx.DB, cfg config.Config)
http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErr := tc.GetHandleErrorsFunc(w, r)
var keysObj tc.DeliveryServiceSSLKeys
@@ -338,7 +339,7 @@ func addDeliveryServiceSSLKeysHandler(db *sqlx.DB, cfg
Config) http.HandlerFunc
}
// fetch the ssl keys for a deliveryservice specified by the fully qualified
hostname
-func getDeliveryServiceSSLKeysByHostNameHandler(db *sqlx.DB, cfg Config)
http.HandlerFunc {
+func getDeliveryServiceSSLKeysByHostNameHandler(db *sqlx.DB, cfg
config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErr := tc.GetHandleErrorsFunc(w, r)
var respBytes []byte
@@ -442,7 +443,7 @@ func getDeliveryServiceSSLKeysByHostNameHandler(db
*sqlx.DB, cfg Config) http.Ha
}
// fetch the deliveryservice ssl keys by the specified xmlID.
-func getDeliveryServiceSSLKeysByXMLIDHandler(db *sqlx.DB, cfg Config)
http.HandlerFunc {
+func getDeliveryServiceSSLKeysByXMLIDHandler(db *sqlx.DB, cfg config.Config)
http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErr := tc.GetHandleErrorsFunc(w, r)
var respBytes []byte
diff --git a/traffic_ops/traffic_ops_golang/routing.go
b/traffic_ops/traffic_ops_golang/routing.go
index a940d5d7f..2fce1bbad 100644
--- a/traffic_ops/traffic_ops_golang/routing.go
+++ b/traffic_ops/traffic_ops_golang/routing.go
@@ -32,6 +32,7 @@ import (
"fmt"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
+
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/config"
"github.com/jmoiron/sqlx"
)
@@ -59,7 +60,7 @@ func getDefaultMiddleware() []Middleware {
// ServerData ...
type ServerData struct {
- Config
+ config.Config
DB *sqlx.DB
}
diff --git a/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
b/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
index dfd5f27bd..cc952814e 100644
--- a/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
+++ b/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
@@ -30,6 +30,7 @@ import (
"github.com/apache/incubator-trafficcontrol/lib/go-log"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/about"
+
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/config"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
@@ -58,10 +59,10 @@ func main() {
os.Exit(1)
}
- var cfg Config
+ var cfg config.Config
var err error
var errorToLog error
- if cfg, err = LoadConfig(*configFileName, *dbConfigFileName,
*riakConfigFileName); err != nil {
+ if cfg, err = config.LoadConfig(*configFileName, *dbConfigFileName,
*riakConfigFileName); err != nil {
if !strings.Contains(err.Error(), "riak conf") {
fmt.Println("Error loading config: " + err.Error())
return
diff --git a/traffic_ops/traffic_ops_golang/urisigning.go
b/traffic_ops/traffic_ops_golang/urisigning.go
index 2fddee819..50679fde0 100644
--- a/traffic_ops/traffic_ops_golang/urisigning.go
+++ b/traffic_ops/traffic_ops_golang/urisigning.go
@@ -31,6 +31,7 @@ import (
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
+
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/config"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/riaksvc"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/tenant"
"github.com/basho/riak-go-client"
@@ -48,7 +49,7 @@ type URISignerKeyset struct {
}
// endpoint handler for fetching uri signing keys from riak
-func getURIsignkeysHandler(db *sqlx.DB, cfg Config) http.HandlerFunc {
+func getURIsignkeysHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErr := tc.GetHandleErrorsFunc(w, r)
@@ -130,7 +131,7 @@ func getURIsignkeysHandler(db *sqlx.DB, cfg Config)
http.HandlerFunc {
}
// Http DELETE handler used to remove urisigning keys assigned to a delivery
service.
-func removeDeliveryServiceURIKeysHandler(db *sqlx.DB, cfg Config)
http.HandlerFunc {
+func removeDeliveryServiceURIKeysHandler(db *sqlx.DB, cfg config.Config)
http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErr := tc.GetHandleErrorsFunc(w, r)
@@ -218,7 +219,7 @@ func removeDeliveryServiceURIKeysHandler(db *sqlx.DB, cfg
Config) http.HandlerFu
}
// Http POST or PUT handler used to store urisigning keys to a delivery
service.
-func saveDeliveryServiceURIKeysHandler(db *sqlx.DB, cfg Config)
http.HandlerFunc {
+func saveDeliveryServiceURIKeysHandler(db *sqlx.DB, cfg config.Config)
http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErr := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/wrappers_test.go
b/traffic_ops/traffic_ops_golang/wrappers_test.go
index ab79ef2c5..4638a8ee2 100644
--- a/traffic_ops/traffic_ops_golang/wrappers_test.go
+++ b/traffic_ops/traffic_ops_golang/wrappers_test.go
@@ -23,6 +23,7 @@ import (
"bytes"
"compress/gzip"
"encoding/json"
+ "flag"
"net/http"
"net/http/httptest"
"testing"
@@ -38,6 +39,8 @@ import (
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"
)
+var debugLogging = flag.Bool("debug", false, "enable debug logging in test")
+
// TestWrapHeaders checks that appropriate default headers are added to a
request
func TestWrapHeaders(t *testing.T) {
body := "We are here!!"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services