rename a few things

This commit is contained in:
davidnewhall2 2020-07-07 02:39:10 -07:00
parent 81f9c8a7d1
commit c3c9043ac7
3 changed files with 15 additions and 15 deletions

View File

@ -13,8 +13,7 @@ import (
// Returns the main index file. // Returns the main index file.
// If index.html becomes a template, this is where it can be compiled. // If index.html becomes a template, this is where it can be compiled.
func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) { func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
index := filepath.Join(s.HTMLPath, "index.html") http.ServeFile(w, r, filepath.Join(s.HTMLPath, "index.html"))
http.ServeFile(w, r, index)
} }
// Arbitrary /health handler. // Arbitrary /health handler.

View File

@ -49,7 +49,7 @@ type Site struct {
Controller string `json:"controller"` Controller string `json:"controller"`
} }
// Events is all the events a plugin has. string = Controller.UUID + text. // Events is all the events a plugin has. string = SiteID + text, or plugin name, or "whatever".
type Events map[string]*EventGroup type Events map[string]*EventGroup
// EventGroup allows each plugin to have a map of events. ie. one map per controller. // EventGroup allows each plugin to have a map of events. ie. one map per controller.
@ -60,14 +60,14 @@ type EventGroup struct {
// Event is like a log message. // Event is like a log message.
type Event struct { type Event struct {
Ts time.Time `json:"ts"` Ts time.Time `json:"ts"` // nolint: stylecheck
Msg string `json:"msg"` Msg string `json:"msg"`
Tags map[string]string `json:"tags,omitempty"` Tags map[string]string `json:"tags,omitempty"`
} }
func (e Events) Groups(filter string) (groups []string) { func (e Events) Groups(prefix string) (groups []string) {
for n := range e { for n := range e {
if filter == "" || strings.HasPrefix(n, filter) { if prefix == "" || strings.HasPrefix(n, prefix) {
groups = append(groups, n) groups = append(groups, n)
} }
} }

View File

@ -66,7 +66,7 @@ func init() { // nolint: gochecknoinits
// Run starts the server and gets things going. // Run starts the server and gets things going.
func (s *Server) Run(c poller.Collect) error { func (s *Server) Run(c poller.Collect) error {
if s.Collect = c; s.Config == nil || s.Port == 0 || s.HTMLPath == "" || !s.Enable { if s.Collect = c; s.Config == nil || s.Port == 0 || s.HTMLPath == "" || !s.Enable {
s.Logf("Web server disabled!") s.Logf("Internal web server disabled!")
return nil return nil
} }
@ -97,11 +97,11 @@ func (s *Server) Start() (err error) {
err = s.server.ListenAndServeTLS(s.SSLCrtPath, s.SSLKeyPath) err = s.server.ListenAndServeTLS(s.SSLCrtPath, s.SSLKeyPath)
} }
if errors.Is(err, http.ErrServerClosed) { if !errors.Is(err, http.ErrServerClosed) {
return nil return err
} }
return err return nil
} }
func (s *Server) newRouter() *mux.Router { func (s *Server) newRouter() *mux.Router {
@ -129,13 +129,14 @@ func (s *Server) newRouter() *mux.Router {
// PasswordIsCorrect returns true if the provided password matches a user's account. // PasswordIsCorrect returns true if the provided password matches a user's account.
func (a accounts) PasswordIsCorrect(user, pass string, ok bool) bool { func (a accounts) PasswordIsCorrect(user, pass string, ok bool) bool {
if len(a) == 0 { // If true then no accounts defined in config; allow anyone. if len(a) == 0 {
return true return true // No accounts defined in config; allow anyone.
} else if !ok { // If true then r.BasicAuth() failed, not a valid user. } else if !ok {
return false return false // r.BasicAuth() failed, not a valid user.
} else if user, ok = a[user]; !ok { // The user var is now the password hash. } else if user, ok = a[user]; !ok { // The user var is now the password hash.
return false return false // The username provided doesn't exist.
} }
// If this is returns nil, the provided password matches, so return true.
return bcrypt.CompareHashAndPassword([]byte(user), []byte(pass)) == nil return bcrypt.CompareHashAndPassword([]byte(user), []byte(pass)) == nil
} }