just fixing some linter issues

This commit is contained in:
Annika Hannig 2021-07-02 14:30:43 +02:00
parent c15f78d76f
commit d75db85e96
No known key found for this signature in database
GPG Key ID: 62E226E47DDCE58D
14 changed files with 86 additions and 82 deletions

View File

@ -17,19 +17,19 @@ func apiStatusShow(_req *http.Request, _params httprouter.Params) (api.Response,
// Handle status
func apiStatus(_req *http.Request, params httprouter.Params) (api.Response, error) {
rsId, err := validateSourceID(params.ByName("id"))
rsID, err := validateSourceID(params.ByName("id"))
if err != nil {
return nil, err
}
source := AliceConfig.SourceInstanceById(rsId)
source := AliceConfig.SourceInstanceByID(rsID)
if source == nil {
return nil, SOURCE_NOT_FOUND_ERROR
}
result, err := source.Status()
if err != nil {
apiLogSourceError("status", rsId, err)
apiLogSourceError("status", rsID, err)
}
return result, err
@ -39,22 +39,22 @@ func apiStatus(_req *http.Request, params httprouter.Params) (api.Response, erro
func apiConfigShow(_req *http.Request, _params httprouter.Params) (api.Response, error) {
result := api.ConfigResponse{
Asn: AliceConfig.Server.Asn,
BgpCommunities: AliceConfig.Ui.BgpCommunities,
RejectReasons: AliceConfig.Ui.RoutesRejections.Reasons,
BgpCommunities: AliceConfig.UI.BgpCommunities,
RejectReasons: AliceConfig.UI.RoutesRejections.Reasons,
Noexport: api.Noexport{
LoadOnDemand: AliceConfig.Ui.RoutesNoexports.LoadOnDemand,
LoadOnDemand: AliceConfig.UI.RoutesNoexports.LoadOnDemand,
},
NoexportReasons: AliceConfig.Ui.RoutesNoexports.Reasons,
NoexportReasons: AliceConfig.UI.RoutesNoexports.Reasons,
RejectCandidates: api.RejectCandidates{
Communities: AliceConfig.Ui.RoutesRejectCandidates.Communities,
Communities: AliceConfig.UI.RoutesRejectCandidates.Communities,
},
Rpki: api.Rpki(AliceConfig.Ui.Rpki),
RoutesColumns: AliceConfig.Ui.RoutesColumns,
RoutesColumnsOrder: AliceConfig.Ui.RoutesColumnsOrder,
NeighboursColumns: AliceConfig.Ui.NeighboursColumns,
NeighboursColumnsOrder: AliceConfig.Ui.NeighboursColumnsOrder,
LookupColumns: AliceConfig.Ui.LookupColumns,
LookupColumnsOrder: AliceConfig.Ui.LookupColumnsOrder,
Rpki: api.Rpki(AliceConfig.UI.Rpki),
RoutesColumns: AliceConfig.UI.RoutesColumns,
RoutesColumnsOrder: AliceConfig.UI.RoutesColumnsOrder,
NeighboursColumns: AliceConfig.UI.NeighboursColumns,
NeighboursColumnsOrder: AliceConfig.UI.NeighboursColumnsOrder,
LookupColumns: AliceConfig.UI.LookupColumns,
LookupColumnsOrder: AliceConfig.UI.LookupColumnsOrder,
PrefixLookupEnabled: AliceConfig.Server.EnablePrefixLookup,
}
return result, nil

View File

@ -14,7 +14,7 @@ func apiNeighborsList(
_req *http.Request,
params httprouter.Params,
) (api.Response, error) {
rsId, err := validateSourceID(params.ByName("id"))
rsID, err := validateSourceID(params.ByName("id"))
if err != nil {
return nil, err
}
@ -23,9 +23,9 @@ func apiNeighborsList(
// Try to fetch neighbors from store, only fall back
// to RS query if store is not ready yet
sourceStatus := AliceNeighboursStore.SourceStatus(rsId)
sourceStatus := AliceNeighboursStore.SourceStatus(rsID)
if sourceStatus.State == STATE_READY {
neighbors := AliceNeighboursStore.GetNeighborsAt(rsId)
neighbors := AliceNeighboursStore.GetNeighborsAt(rsID)
// Make response
neighborsResponse = &api.NeighboursResponse{
Api: api.ApiStatus{
@ -41,14 +41,14 @@ func apiNeighborsList(
Neighbours: neighbors,
}
} else {
source := AliceConfig.SourceInstanceById(rsId)
source := AliceConfig.SourceInstanceByID(rsID)
if source == nil {
return nil, SOURCE_NOT_FOUND_ERROR
}
neighborsResponse, err = source.Neighbours()
if err != nil {
apiLogSourceError("neighbors", rsId, err)
apiLogSourceError("neighbors", rsID, err)
return nil, err
}
}

View File

@ -11,20 +11,20 @@ import (
// Handle routes
func apiRoutesList(_req *http.Request, params httprouter.Params) (api.Response, error) {
rsId, err := validateSourceID(params.ByName("id"))
rsID, err := validateSourceID(params.ByName("id"))
if err != nil {
return nil, err
}
neighborId := params.ByName("neighborId")
neighborID := params.ByName("neighborId")
source := AliceConfig.SourceInstanceById(rsId)
source := AliceConfig.SourceInstanceByID(rsID)
if source == nil {
return nil, SOURCE_NOT_FOUND_ERROR
}
result, err := source.Routes(neighborId)
result, err := source.Routes(neighborID)
if err != nil {
apiLogSourceError("routes", rsId, neighborId, err)
apiLogSourceError("routes", rsID, neighborID, err)
}
return result, err
@ -38,20 +38,20 @@ func apiRoutesListReceived(
// Measure response time
t0 := time.Now()
rsId, err := validateSourceID(params.ByName("id"))
rsID, err := validateSourceID(params.ByName("id"))
if err != nil {
return nil, err
}
neighborId := params.ByName("neighborId")
source := AliceConfig.SourceInstanceById(rsId)
neighborID := params.ByName("neighborId")
source := AliceConfig.SourceInstanceByID(rsID)
if source == nil {
return nil, SOURCE_NOT_FOUND_ERROR
}
result, err := source.RoutesReceived(neighborId)
result, err := source.RoutesReceived(neighborID)
if err != nil {
apiLogSourceError("routes_received", rsId, neighborId, err)
apiLogSourceError("routes_received", rsID, neighborID, err)
return nil, err
}
@ -80,7 +80,7 @@ func apiRoutesListReceived(
// Paginate results
page := apiQueryMustInt(req, "page", 0)
pageSize := AliceConfig.Ui.Pagination.RoutesAcceptedPageSize
pageSize := AliceConfig.UI.Pagination.RoutesAcceptedPageSize
routes, pagination := apiPaginateRoutes(routes, page, pageSize)
// Calculate query duration
@ -111,20 +111,20 @@ func apiRoutesListFiltered(
) (api.Response, error) {
t0 := time.Now()
rsId, err := validateSourceID(params.ByName("id"))
rsID, err := validateSourceID(params.ByName("id"))
if err != nil {
return nil, err
}
neighborId := params.ByName("neighborId")
source := AliceConfig.SourceInstanceById(rsId)
neighborID := params.ByName("neighborId")
source := AliceConfig.SourceInstanceByID(rsID)
if source == nil {
return nil, SOURCE_NOT_FOUND_ERROR
}
result, err := source.RoutesFiltered(neighborId)
result, err := source.RoutesFiltered(neighborID)
if err != nil {
apiLogSourceError("routes_filtered", rsId, neighborId, err)
apiLogSourceError("routes_filtered", rsID, neighborID, err)
return nil, err
}
@ -153,7 +153,7 @@ func apiRoutesListFiltered(
// Paginate results
page := apiQueryMustInt(req, "page", 0)
pageSize := AliceConfig.Ui.Pagination.RoutesFilteredPageSize
pageSize := AliceConfig.UI.Pagination.RoutesFilteredPageSize
routes, pagination := apiPaginateRoutes(routes, page, pageSize)
// Calculate query duration
@ -184,20 +184,20 @@ func apiRoutesListNotExported(
) (api.Response, error) {
t0 := time.Now()
rsId, err := validateSourceID(params.ByName("id"))
rsID, err := validateSourceID(params.ByName("id"))
if err != nil {
return nil, err
}
neighborId := params.ByName("neighborId")
source := AliceConfig.SourceInstanceById(rsId)
neighborID := params.ByName("neighborId")
source := AliceConfig.SourceInstanceByID(rsID)
if source == nil {
return nil, SOURCE_NOT_FOUND_ERROR
}
result, err := source.RoutesNotExported(neighborId)
result, err := source.RoutesNotExported(neighborID)
if err != nil {
apiLogSourceError("routes_not_exported", rsId, neighborId, err)
apiLogSourceError("routes_not_exported", rsID, neighborID, err)
return nil, err
}
@ -226,7 +226,7 @@ func apiRoutesListNotExported(
// Paginate results
page := apiQueryMustInt(req, "page", 0)
pageSize := AliceConfig.Ui.Pagination.RoutesNotExportedPageSize
pageSize := AliceConfig.UI.Pagination.RoutesNotExportedPageSize
routes, pagination := apiPaginateRoutes(routes, page, pageSize)
// Calculate query duration

View File

@ -17,7 +17,7 @@ func apiRouteserversList(_req *http.Request, _params httprouter.Params) (api.Res
sources := AliceConfig.Sources
for _, source := range sources {
routeservers = append(routeservers, api.Routeserver{
Id: source.Id,
Id: source.ID,
Type: source.Type,
Name: source.Name,
Group: source.Group,

View File

@ -89,13 +89,13 @@ func apiLookupPrefixGlobal(
// Paginate results
pageImported := apiQueryMustInt(req, "page_imported", 0)
pageSizeImported := AliceConfig.Ui.Pagination.RoutesAcceptedPageSize
pageSizeImported := AliceConfig.UI.Pagination.RoutesAcceptedPageSize
routesImported, paginationImported := apiPaginateLookupRoutes(
imported, pageImported, pageSizeImported,
)
pageFiltered := apiQueryMustInt(req, "page_filtered", 0)
pageSizeFiltered := AliceConfig.Ui.Pagination.RoutesFilteredPageSize
pageSizeFiltered := AliceConfig.UI.Pagination.RoutesFilteredPageSize
routesFiltered, paginationFiltered := apiPaginateLookupRoutes(
filtered, pageFiltered, pageSizeFiltered,
)

View File

@ -12,7 +12,7 @@ func apiLogSourceError(module string, sourceID string, params ...interface{}) {
args := []string{}
// Get source configuration
source := AliceConfig.SourceById(sourceID)
source := AliceConfig.SourceByID(sourceID)
sourceName := "unknown"
if source != nil {
sourceName = source.Name

View File

@ -15,7 +15,7 @@ func StartHTTPServer() {
router := httprouter.New()
// Serve static content
if err := webRegisterAssets(AliceConfig.Ui, router); err != nil {
if err := webRegisterAssets(AliceConfig.UI, router); err != nil {
log.Fatal(err)
}

View File

@ -83,8 +83,8 @@ type RpkiConfig struct {
Invalid []string `ini:"invalid"`
}
// UiConfig holds runtime settings for the web client
type UiConfig struct {
// UIConfig holds runtime settings for the web client
type UIConfig struct {
RoutesColumns map[string]string
RoutesColumnsOrder []string
@ -121,7 +121,7 @@ type PaginationConfig struct {
// A SourceConfig is a generic source configuration
type SourceConfig struct {
Id string
ID string
Order int
Name string
Group string
@ -143,24 +143,24 @@ type SourceConfig struct {
type Config struct {
Server ServerConfig
Housekeeping HousekeepingConfig
Ui UiConfig
UI UIConfig
Sources []*SourceConfig
File string
}
// SourceById returns a source from the config by id
func (cfg *Config) SourceById(sourceId string) *SourceConfig {
// SourceByID returns a source from the config by id
func (cfg *Config) SourceByID(id string) *SourceConfig {
for _, sourceConfig := range cfg.Sources {
if sourceConfig.Id == sourceId {
if sourceConfig.ID == id {
return sourceConfig
}
}
return nil
}
// SourceInstanceById returns an instance by id
func (cfg *Config) SourceInstanceById(sourceId string) sources.Source {
sourceConfig := cfg.SourceById(sourceId)
// SourceInstanceByID returns an instance by id
func (cfg *Config) SourceInstanceByID(id string) sources.Source {
sourceConfig := cfg.SourceByID(id)
if sourceConfig == nil {
return nil // Nothing to do here.
}
@ -516,8 +516,8 @@ func getPaginationConfig(config *ini.File) PaginationConfig {
}
// Get the UI configuration from the config file
func getUiConfig(config *ini.File) (UiConfig, error) {
uiConfig := UiConfig{}
func getUIConfig(config *ini.File) (UIConfig, error) {
uiConfig := UIConfig{}
// Get route columns
routesColumns, routesColumnsOrder, err := getRoutesColumns(config)
@ -567,7 +567,7 @@ func getUiConfig(config *ini.File) (UiConfig, error) {
paginationConfig := getPaginationConfig(config)
// Make config
uiConfig = UiConfig{
uiConfig = UIConfig{
RoutesColumns: routesColumns,
RoutesColumnsOrder: routesColumnsOrder,
@ -632,7 +632,7 @@ func getSources(config *ini.File) ([]*SourceConfig, error) {
section.Key("blackholes").MustString(""))
config := &SourceConfig{
Id: sourceID,
ID: sourceID,
Order: order,
Name: sourceName,
Group: sourceGroup,
@ -658,7 +658,7 @@ func getSources(config *ini.File) ([]*SourceConfig, error) {
"and pipe_protocol_prefix", pipeProtocolPrefix)
c := birdwatcher.Config{
Id: config.Id,
ID: config.ID,
Name: config.Name,
Timezone: "UTC",
@ -677,7 +677,7 @@ func getSources(config *ini.File) ([]*SourceConfig, error) {
case SourceTypeGoBGP:
c := gobgp.Config{
Id: config.Id,
Id: config.ID,
Name: config.Name,
}
@ -692,7 +692,7 @@ func getSources(config *ini.File) ([]*SourceConfig, error) {
case SourceTypeOpenBGPD:
c := openbgpd.Config{
ID: config.Id,
ID: config.ID,
Name: config.Name,
}
backendConfig.MapTo(&c)
@ -749,7 +749,7 @@ func loadConfig(file string) (*Config, error) {
}
// Get UI configurations
ui, err := getUiConfig(parsedConfig)
ui, err := getUIConfig(parsedConfig)
if err != nil {
return nil, err
}
@ -757,7 +757,7 @@ func loadConfig(file string) (*Config, error) {
config := &Config{
Server: server,
Housekeeping: housekeeping,
Ui: ui,
UI: ui,
Sources: sources,
File: file,
}

View File

@ -25,6 +25,7 @@ type NeighboursStore struct {
sync.RWMutex
}
// NewNeighboursStore creates a new store for neighbors
func NewNeighboursStore(config *Config) *NeighboursStore {
// Build source mapping
@ -33,13 +34,13 @@ func NewNeighboursStore(config *Config) *NeighboursStore {
statusMap := make(map[string]StoreStatus)
for _, source := range config.Sources {
sourceId := source.Id
configMap[sourceId] = source
statusMap[sourceId] = StoreStatus{
id := source.ID
configMap[id] = source
statusMap[id] = StoreStatus{
State: STATE_INIT,
}
neighboursMap[sourceId] = make(NeighboursIndex)
neighboursMap[id] = make(NeighboursIndex)
}
// Set refresh interval, default to 5 minutes when
@ -62,6 +63,7 @@ func NewNeighboursStore(config *Config) *NeighboursStore {
return store
}
// Start the store's housekeeping.
func (self *NeighboursStore) Start() {
log.Println("Starting local neighbours store")
log.Println("Neighbours Store refresh interval set to:", self.refreshInterval)
@ -121,7 +123,7 @@ func (self *NeighboursStore) update() {
if err != nil {
log.Println(
"Refreshing the neighbors store failed for:",
sourceConfig.Name, "(", sourceConfig.Id, ")",
sourceConfig.Name, "(", sourceConfig.ID, ")",
"with:", err,
"- NEXT STATE: ERROR",
)

View File

@ -33,7 +33,7 @@ func NewRoutesStore(config *Config) *RoutesStore {
configMap := make(map[string]*SourceConfig)
for _, source := range config.Sources {
id := source.Id
id := source.ID
configMap[id] = source
routesMap[id] = &api.RoutesResponse{}
@ -109,7 +109,7 @@ func (rs *RoutesStore) update() {
if err != nil {
log.Println(
"Refreshing the routes store failed for:", sourceConfig.Name,
"(", sourceConfig.Id, ")",
"(", sourceConfig.ID, ")",
"with:", err,
"- NEXT STATE: ERROR",
)
@ -207,7 +207,7 @@ func routeToLookupRoute(
) *api.LookupRoute {
// Get neighbour
neighbour := AliceNeighboursStore.GetNeighbourAt(source.Id, route.NeighbourId)
neighbour := AliceNeighboursStore.GetNeighbourAt(source.ID, route.NeighbourId)
// Make route
lookup := &api.LookupRoute{
@ -217,7 +217,7 @@ func routeToLookupRoute(
Neighbour: neighbour,
Routeserver: api.Routeserver{
Id: source.Id,
Id: source.ID,
Name: source.Name,
},

View File

@ -34,7 +34,7 @@ func webPrepareClientHTML(html string) string {
// Register assets handler and index handler
// at /static and /
func webRegisterAssets(ui UiConfig, router *httprouter.Router) error {
func webRegisterAssets(ui UIConfig, router *httprouter.Router) error {
log.Println("Preparing and installing assets")
// Prepare client html: Rewrite paths

View File

@ -1,10 +1,12 @@
package birdwatcher
// Config contains all configuration attributes
// for a birdwatcher based source.
type Config struct {
Id string
ID string
Name string
Api string `ini:"api"`
API string `ini:"api"`
Timezone string `ini:"timezone"`
ServerTime string `ini:"servertime"`
ServerTimeShort string `ini:"servertime_short"`

View File

@ -153,7 +153,7 @@ func parseRelativeServerTime(uptime interface{}, config Config) time.Duration {
// Parse neighbours response
func parseNeighbours(bird ClientResponse, config Config) (api.Neighbours, error) {
rsId := config.Id
rsId := config.ID
neighbours := api.Neighbours{}
protocols := bird["protocols"].(map[string]interface{})

View File

@ -30,7 +30,7 @@ type GenericBirdwatcher struct {
}
func NewBirdwatcher(config Config) Birdwatcher {
client := NewClient(config.Api)
client := NewClient(config.API)
// Cache settings:
// TODO: Maybe read from config file
@ -248,7 +248,7 @@ func (self *GenericBirdwatcher) NeighboursStatus() (*api.NeighboursStatusRespons
func (self *GenericBirdwatcher) LookupPrefix(prefix string) (*api.RoutesLookupResponse, error) {
// Get RS info
rs := api.Routeserver{
Id: self.config.Id,
Id: self.config.ID,
Name: self.config.Name,
}