dangogh closed pull request #1828: Cleaned up golint warnings
URL: https://github.com/apache/incubator-trafficcontrol/pull/1828
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/asns.go
b/traffic_ops/traffic_ops_golang/asns.go
index 3181e51912..8d0ea23e95 100644
--- a/traffic_ops/traffic_ops_golang/asns.go
+++ b/traffic_ops/traffic_ops_golang/asns.go
@@ -31,8 +31,10 @@ import (
"github.com/jmoiron/sqlx"
)
+// ASNsPrivLevel ...
const ASNsPrivLevel = 10
+// ASNsHandler ...
func ASNsHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/auth/authorize.go
b/traffic_ops/traffic_ops_golang/auth/authorize.go
index e1a5c772e6..712dc28505 100644
--- a/traffic_ops/traffic_ops_golang/auth/authorize.go
+++ b/traffic_ops/traffic_ops_golang/auth/authorize.go
@@ -56,7 +56,9 @@ const PrivLevelAdmin = 30
// TenantIDInvalid - The default Tenant ID
const TenantIDInvalid = -1
-const CurrentUserKey = "currentUser"
+type key int
+
+const CurrentUserKey key = iota
// GetCurrentUserFromDB - returns the id and privilege level of the given
user along with the username, or -1 as the id, - as the userName and
PrivLevelInvalid if the user doesn't exist.
func GetCurrentUserFromDB(CurrentUserStmt *sqlx.Stmt, user string) CurrentUser
{
diff --git a/traffic_ops/traffic_ops_golang/config.go
b/traffic_ops/traffic_ops_golang/config.go
index 2d9ad2849b..8b47610f64 100644
--- a/traffic_ops/traffic_ops_golang/config.go
+++ b/traffic_ops/traffic_ops_golang/config.go
@@ -155,7 +155,7 @@ func LoadConfig(cdnConfPath string, dbConfPath string,
riakConfPath string) (Con
return cfg, err
}
-// CertPath extracts path to cert .cert file
+// GetCertPath - extracts path to cert .cert file
func (c Config) GetCertPath() string {
v, ok := c.URL.Query()["cert"]
if ok {
@@ -164,7 +164,7 @@ func (c Config) GetCertPath() string {
return ""
}
-// KeyPath extracts path to cert .key file
+// GetKeyPath - extracts path to cert .key file
func (c Config) GetKeyPath() string {
v, ok := c.URL.Query()["key"]
if ok {
@@ -181,6 +181,7 @@ func getRiakAuthOptions(s string) (*riak.AuthOptions,
error) {
}
const (
+ // MojoliciousConcurrentConnectionsDefault ...
MojoliciousConcurrentConnectionsDefault = 12
)
diff --git a/traffic_ops/traffic_ops_golang/deliveryservices_keys.go
b/traffic_ops/traffic_ops_golang/deliveryservices_keys.go
index 3c4e34d2e3..ee2b870fa0 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservices_keys.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservices_keys.go
@@ -167,7 +167,7 @@ func verifyAndEncodeCertificate(certificate string, rootCA
string) (string, erro
pemCerts := make([]byte, base64.StdEncoding.EncodedLen(len(b64crt)))
_, err := base64.StdEncoding.Decode(pemCerts, []byte(b64crt))
if err != nil {
- return "", fmt.Errorf("ERROR: could not base64 decode the
certificate, %v\n", err)
+ return "", fmt.Errorf("could not base64 decode the certificate
%v", err)
}
// decode, verify, and order certs for storgae
@@ -178,10 +178,10 @@ func verifyAndEncodeCertificate(certificate string,
rootCA string) (string, erro
block, _ := pem.Decode([]byte(certs[0]))
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
- return "", fmt.Errorf("ERROR: could not parse the
server certificate, %v\n", err)
+ return "", fmt.Errorf("could not parse the server
certificate %v", err)
}
if !(cert.KeyUsage&x509.KeyUsageKeyEncipherment > 0) {
- return "", fmt.Errorf("ERROR: no key encipherment usage
for the server certificate\n")
+ return "", fmt.Errorf("no key encipherment usage for
the server certificate")
}
for i := 0; i < len(certs)-1; i++ {
bundle += certs[i]
@@ -192,13 +192,13 @@ func verifyAndEncodeCertificate(certificate string,
rootCA string) (string, erro
rootPool := x509.NewCertPool()
if rootCA != "" {
if !rootPool.AppendCertsFromPEM([]byte(rootCA)) {
- return "", fmt.Errorf("ERROR: root CA
certificate is empty, %v\n", err)
+ return "", fmt.Errorf("root CA certificate is
empty, %v", err)
}
}
intermediatePool := x509.NewCertPool()
if !intermediatePool.AppendCertsFromPEM([]byte(bundle)) {
- return "", fmt.Errorf("ERROR: certificate CA bundle is
empty, %v\n", err)
+ return "", fmt.Errorf("certificate CA bundle is empty,
%v", err)
}
if rootCA != "" {
@@ -215,7 +215,7 @@ func verifyAndEncodeCertificate(certificate string, rootCA
string) (string, erro
chain, err := cert.Verify(opts)
if err != nil {
- return "", fmt.Errorf("ERROR: could verify the
certificate chain, %v\n", err)
+ return "", fmt.Errorf("could verify the certificate
chain %v", err)
}
if len(chain) > 0 {
for _, link := range chain[0] {
@@ -289,7 +289,7 @@ func addDeliveryServiceSSLKeysHandler(db *sqlx.DB, cfg
Config) http.HandlerFunc
keysObj.Certificate.Crt = certChain
// marshal the keysObj
- keysJson, err := json.Marshal(&keysObj)
+ keysJSON, err := json.Marshal(&keysObj)
if err != nil {
log.Errorf("ERROR: could not marshal the keys object,
%v\n", err)
handleErr(http.StatusBadRequest, err)
@@ -318,7 +318,7 @@ func addDeliveryServiceSSLKeysHandler(db *sqlx.DB, cfg
Config) http.HandlerFunc
Charset: "utf-8",
ContentEncoding: "utf-8",
Key: keysObj.DeliveryService,
- Value: []byte(keysJson),
+ Value: []byte(keysJSON),
}
err = saveObject(obj, SSLKeysBucket, cluster)
@@ -329,7 +329,7 @@ func addDeliveryServiceSSLKeysHandler(db *sqlx.DB, cfg
Config) http.HandlerFunc
}
w.Header().Set("Content-Type", "application/json")
- fmt.Fprintf(w, "%s", keysJson)
+ fmt.Fprintf(w, "%s", keysJSON)
}
}
diff --git a/traffic_ops/traffic_ops_golang/monitoring.go
b/traffic_ops/traffic_ops_golang/monitoring.go
index 7835b0b5c8..fd3ba8c115 100644
--- a/traffic_ops/traffic_ops_golang/monitoring.go
+++ b/traffic_ops/traffic_ops_golang/monitoring.go
@@ -34,14 +34,28 @@ import (
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
)
+// CacheMonitorConfigFile ...
const CacheMonitorConfigFile = "rascal.properties"
+
+// MonitorType ...
const MonitorType = "RASCAL"
+
+// RouterType ...
const RouterType = "CCR"
+
+// MonitorProfilePrefix ...
const MonitorProfilePrefix = "RASCAL"
+
+// MonitorConfigFile ...
const MonitorConfigFile = "rascal-config.txt"
+
+// KilobitsPerMegabit ...
const KilobitsPerMegabit = 1000
+
+// DeliveryServiceStatus ...
const DeliveryServiceStatus = "REPORTED"
+// BasicServer ...
type BasicServer struct {
Profile string `json:"profile"`
Status string `json:"status"`
@@ -53,10 +67,12 @@ type BasicServer struct {
FQDN string `json:"fqdn"`
}
+// Monitor ...
type Monitor struct {
BasicServer
}
+// Cache ...
type Cache struct {
BasicServer
InterfaceName string `json:"interfacename"`
@@ -64,22 +80,26 @@ type Cache struct {
HashID string `json:"hashid"`
}
+// Cachegroup ...
type Cachegroup struct {
Name string `json:"name"`
Coordinates Coordinates `json:"coordinates"`
}
+// Coordinates ...
type Coordinates struct {
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
}
+// Profile ...
type Profile struct {
Name string `json:"name"`
Type string `json:"type"`
Parameters map[string]interface{} `json:"parameters"`
}
+// Monitoring ...
type Monitoring struct {
TrafficServers []Cache `json:"trafficServers"`
TrafficMonitors []Monitor `json:"trafficMonitors"`
@@ -89,15 +109,18 @@ type Monitoring struct {
Config map[string]interface{} `json:"config"`
}
+// MonitoringResponse ...
type MonitoringResponse struct {
Response Monitoring `json:"response"`
}
+// Router ...
type Router struct {
Type string
Profile string
}
+// DeliveryService ...
type DeliveryService struct {
XMLID string `json:"xmlId"`
TotalTPSThreshold float64 `json:"totalTpsThreshold"`
diff --git a/traffic_ops/traffic_ops_golang/parameters.go
b/traffic_ops/traffic_ops_golang/parameters.go
index e3c97e7773..8025403889 100644
--- a/traffic_ops/traffic_ops_golang/parameters.go
+++ b/traffic_ops/traffic_ops_golang/parameters.go
@@ -131,6 +131,7 @@ LEFT JOIN profile pr ON pp.profile = pr.id`
return query
}
+// ParametersGroupBy ...
func ParametersGroupBy() string {
groupBy := ` GROUP BY p.config_file, p.id, p.last_updated, p.name,
p.value, p.secure`
return groupBy
diff --git a/traffic_ops/traffic_ops_golang/regions.go
b/traffic_ops/traffic_ops_golang/regions.go
index 3b06f23810..7f8f85dbda 100644
--- a/traffic_ops/traffic_ops_golang/regions.go
+++ b/traffic_ops/traffic_ops_golang/regions.go
@@ -31,7 +31,6 @@ import (
"github.com/jmoiron/sqlx"
)
-
func regionsHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/riak.go
b/traffic_ops/traffic_ops_golang/riak.go
index 142c2e4a59..cfd33f3869 100644
--- a/traffic_ops/traffic_ops_golang/riak.go
+++ b/traffic_ops/traffic_ops_golang/riak.go
@@ -37,33 +37,38 @@ const RiakPort = 8087
// CDNURIKeysBucket is the namespace or bucket used for CDN URI signing keys.
const CDNURIKeysBucket = "cdn_uri_sig_keys"
-// SSLKeysBucket
+// SSLKeysBucket ...
const SSLKeysBucket = "ssl"
// 5 second timeout
const timeOut = time.Second * 5
-// maximum command execution attempts
+// MaxCommandExecutionAttempts ...
const MaxCommandExecutionAttempts = 5
+// StorageCluster ...
type StorageCluster interface {
Start() error
Stop() error
Execute(riak.Command) error
}
+// RiakStorageCluster ...
type RiakStorageCluster struct {
Cluster *riak.Cluster
}
+// Stop ...
func (ri RiakStorageCluster) Stop() error {
return ri.Cluster.Stop()
}
+// Start ...
func (ri RiakStorageCluster) Start() error {
return ri.Cluster.Start()
}
+// Execute ...
func (ri RiakStorageCluster) Execute(command riak.Command) error {
return ri.Cluster.Execute(command)
}
@@ -89,7 +94,10 @@ func deleteObject(key string, bucket string, cluster
StorageCluster) error {
if err != nil {
return err
}
- if err := cluster.Execute(cmd); err != nil {
+
+ err = cluster.Execute(cmd)
+
+ if err != nil {
return err
}
@@ -140,7 +148,8 @@ func saveObject(obj *riak.Object, bucket string, cluster
StorageCluster) error {
if err != nil {
return err
}
- if err := cluster.Execute(cmd); err != nil {
+ err = cluster.Execute(cmd)
+ if err != nil {
return err
}
diff --git a/traffic_ops/traffic_ops_golang/routes.go
b/traffic_ops/traffic_ops_golang/routes.go
index f3cac4156e..dbb7150056 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -35,7 +35,10 @@ import (
"github.com/basho/riak-go-client"
)
+// Authenticated ...
var Authenticated = true
+
+// NoAuth ...
var NoAuth = false
func handlerToFunc(handler http.Handler) http.HandlerFunc {
@@ -156,6 +159,7 @@ func CreateThrottledHandler(handler http.Handler,
maxConcurrentCalls int) Thrott
return ThrottledHandler{handler, make(chan struct{},
maxConcurrentCalls)}
}
+// ThrottledHandler ...
type ThrottledHandler struct {
Handler http.Handler
ReqChan chan struct{}
diff --git a/traffic_ops/traffic_ops_golang/routing.go
b/traffic_ops/traffic_ops_golang/routing.go
index fcca8da082..af6f25d4be 100644
--- a/traffic_ops/traffic_ops_golang/routing.go
+++ b/traffic_ops/traffic_ops_golang/routing.go
@@ -35,10 +35,13 @@ import (
"github.com/jmoiron/sqlx"
)
+// RoutePrefix ...
const RoutePrefix = "api" // TODO config?
+// Middleware ...
type Middleware func(handlerFunc http.HandlerFunc) http.HandlerFunc
+// Route ...
type Route struct {
// Order matters! Do not reorder this! Routes() uses positional
construction for readability.
Version float64
@@ -54,11 +57,13 @@ func getDefaultMiddleware() []Middleware {
return []Middleware{wrapHeaders}
}
+// ServerData ...
type ServerData struct {
Config
DB *sqlx.DB
}
+// CompiledRoute ...
type CompiledRoute struct {
Handler http.HandlerFunc
Regex *regexp.Regexp
@@ -78,6 +83,7 @@ func getSortedRouteVersions(rs []Route) []float64 {
return versions
}
+// PathHandler ...
type PathHandler struct {
Path string
Handler http.HandlerFunc
@@ -116,7 +122,7 @@ func CreateRouteMap(rs []Route, authBase AuthBase)
map[string][]PathHandler {
return m
}
-// CompiledRoutes takes a map of methods to paths and handlers, and returns a
map of methods to CompiledRoutes.
+// CompileRoutes - takes a map of methods to paths and handlers, and returns a
map of methods to CompiledRoutes
func CompileRoutes(routes map[string][]PathHandler) map[string][]CompiledRoute
{
compiledRoutes := map[string][]CompiledRoute{}
for method, mRoutes := range routes {
@@ -141,6 +147,7 @@ func CompileRoutes(routes map[string][]PathHandler)
map[string][]CompiledRoute {
return compiledRoutes
}
+// Handler - generic handler func used by the Handlers hooking into the routes
func Handler(routes map[string][]CompiledRoute, catchall http.Handler, w
http.ResponseWriter, r *http.Request) {
requested := r.URL.Path[1:]
@@ -170,6 +177,7 @@ func Handler(routes map[string][]CompiledRoute, catchall
http.Handler, w http.Re
catchall.ServeHTTP(w, r)
}
+// RegisterRoutes - parses the routes and registers the handlers with the Go
Router
func RegisterRoutes(d ServerData) error {
routeSlice, catchall, err := Routes(d)
if err != nil {
diff --git a/traffic_ops/traffic_ops_golang/routing_test.go
b/traffic_ops/traffic_ops_golang/routing_test.go
index e3ed1870da..4b1efa6c06 100644
--- a/traffic_ops/traffic_ops_golang/routing_test.go
+++ b/traffic_ops/traffic_ops_golang/routing_test.go
@@ -32,10 +32,14 @@ import (
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
)
+type key int
+
+const AuthWasCalled key = iota
+
func TestCreateRouteMap(t *testing.T) {
authBase := AuthBase{false, "secret", nil, func(handlerFunc
http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
- ctx := context.WithValue(r.Context(), "authWasCalled",
"true")
+ ctx := context.WithValue(r.Context(), AuthWasCalled,
"true")
handlerFunc(w, r.WithContext(ctx))
}
}}
diff --git a/traffic_ops/traffic_ops_golang/servers.go
b/traffic_ops/traffic_ops_golang/servers.go
index 4e7e776fd5..1d2f34e43a 100644
--- a/traffic_ops/traffic_ops_golang/servers.go
+++ b/traffic_ops/traffic_ops_golang/servers.go
@@ -61,7 +61,7 @@ func serversHandler(db *sqlx.DB) http.HandlerFunc {
if k == `id` {
if _, err := strconv.Atoi(v); err != nil {
log.Errorf("Expected {id} to be an
integer: %s", v)
- handleErrs(http.StatusNotFound,
errors.New("Resource not found.")) //matches perl response
+ handleErrs(http.StatusNotFound,
errors.New("Resource not found")) //matches perl response
return
}
}
diff --git a/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
b/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
index 0726e0d2cc..5f9e0ea539 100644
--- a/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
+++ b/traffic_ops/traffic_ops_golang/traffic_ops_golang.go
@@ -34,6 +34,7 @@ import (
_ "github.com/lib/pq"
)
+// Version ...
const Version = "0.1"
func main() {
diff --git a/traffic_ops/traffic_ops_golang/wrappers.go
b/traffic_ops/traffic_ops_golang/wrappers.go
index 7c5707a75e..410c2fe8a8 100644
--- a/traffic_ops/traffic_ops_golang/wrappers.go
+++ b/traffic_ops/traffic_ops_golang/wrappers.go
@@ -38,8 +38,10 @@ import (
"github.com/jmoiron/sqlx"
)
+// ServerName - the server identifier
const ServerName = "traffic_ops_golang" + "/" + Version
+// AuthBase ...
type AuthBase struct {
noAuth bool
secret string
@@ -47,6 +49,7 @@ type AuthBase struct {
override Middleware
}
+// GetWrapper ...
func (a AuthBase) GetWrapper(privLevelRequired int) Middleware {
if a.override != nil {
return a.override
@@ -129,6 +132,7 @@ func wrapHeaders(h http.HandlerFunc) http.HandlerFunc {
}
}
+// AccessLogTimeFormat ...
const AccessLogTimeFormat = "02/Jan/2006:15:04:05 -0700"
func wrapAccessLog(secret string, h http.Handler) http.HandlerFunc {
@@ -219,17 +223,20 @@ func stripAllWhitespace(s string) string {
}, s)
}
+// Interceptor ...
type Interceptor struct {
w http.ResponseWriter
code int
byteCount int
}
+// WriteHeader ...
func (i *Interceptor) WriteHeader(rc int) {
i.w.WriteHeader(rc)
i.code = rc
}
+// Write ...
func (i *Interceptor) Write(b []byte) (int, error) {
wi, werr := i.w.Write(b)
i.byteCount += wi
@@ -239,6 +246,7 @@ func (i *Interceptor) Write(b []byte) (int, error) {
return wi, werr
}
+// Header ...
func (i *Interceptor) Header() http.Header {
return i.w.Header()
}
@@ -249,20 +257,29 @@ type BodyInterceptor struct {
body []byte
}
+// WriteHeader ...
func (i *BodyInterceptor) WriteHeader(rc int) {
i.w.WriteHeader(rc)
}
+
+// Write ...
func (i *BodyInterceptor) Write(b []byte) (int, error) {
i.body = append(i.body, b...)
return len(b), nil
}
+
+// Header ...
func (i *BodyInterceptor) Header() http.Header {
return i.w.Header()
}
+
+// RealWrite ...
func (i *BodyInterceptor) RealWrite(b []byte) (int, error) {
wi, werr := i.w.Write(i.body)
return wi, werr
}
+
+// Body ...
func (i *BodyInterceptor) Body() []byte {
return i.body
}
----------------------------------------------------------------
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