mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
dashboard, vendor: gofmt, govendor, use vendored file watcher
This commit is contained in:
parent
64d4117af7
commit
8e3310aa1b
6 changed files with 174 additions and 23 deletions
|
|
@ -17,17 +17,17 @@
|
||||||
package dashboard
|
package dashboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/fsnotify/fsnotify"
|
|
||||||
"github.com/mohae/deepcopy"
|
"github.com/mohae/deepcopy"
|
||||||
|
"github.com/rjeczalik/notify"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
"bytes"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var emptyChunk = json.RawMessage("[]")
|
var emptyChunk = json.RawMessage("[]")
|
||||||
|
|
@ -183,17 +183,12 @@ func (db *Dashboard) streamLogs() {
|
||||||
}
|
}
|
||||||
db.lock.Unlock()
|
db.lock.Unlock()
|
||||||
|
|
||||||
watcher, err := fsnotify.NewWatcher()
|
watcher := make(chan notify.EventInfo, 10)
|
||||||
if err != nil {
|
if err := notify.Watch(db.logdir, watcher, notify.Create); err != nil {
|
||||||
log.Warn("Failed to create fs watcher", "err", err)
|
log.Warn("Failed to create file system watcher", "err", err)
|
||||||
return
|
|
||||||
}
|
|
||||||
defer watcher.Close()
|
|
||||||
err = watcher.Add(db.logdir)
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("Failed to add logdir to fs watcher", "logdir", db.logdir, "err", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer notify.Stop(watcher)
|
||||||
|
|
||||||
ticker := time.NewTicker(db.config.Refresh)
|
ticker := time.NewTicker(db.config.Refresh)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
@ -201,9 +196,9 @@ func (db *Dashboard) streamLogs() {
|
||||||
loop:
|
loop:
|
||||||
for err == nil || errc == nil {
|
for err == nil || errc == nil {
|
||||||
select {
|
select {
|
||||||
case event := <-watcher.Events:
|
case event := <-watcher:
|
||||||
// Make sure that new log file was created.
|
// Make sure that new log file was created.
|
||||||
if event.Op&fsnotify.Create == 0 || !re.Match([]byte(event.Name)) {
|
if !re.Match([]byte(event.Path())) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if opened == nil {
|
if opened == nil {
|
||||||
|
|
@ -212,7 +207,7 @@ loop:
|
||||||
}
|
}
|
||||||
// The new log file's name is always greater,
|
// The new log file's name is always greater,
|
||||||
// because it is created using the actual log record's time.
|
// because it is created using the actual log record's time.
|
||||||
if opened.Name() >= event.Name {
|
if opened.Name() >= event.Path() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Read the rest of the previously opened file.
|
// Read the rest of the previously opened file.
|
||||||
|
|
@ -232,8 +227,8 @@ loop:
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if opened, err = os.OpenFile(event.Name, os.O_RDONLY, 0644); err != nil {
|
if opened, err = os.OpenFile(event.Path(), os.O_RDONLY, 0644); err != nil {
|
||||||
log.Warn("Failed to open file", "name", event.Name, "err", err)
|
log.Warn("Failed to open file", "name", event.Path(), "err", err)
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
buf = buf[:0]
|
buf = buf[:0]
|
||||||
|
|
@ -248,10 +243,6 @@ loop:
|
||||||
db.history.Logs.Source.Name = fi.Name()
|
db.history.Logs.Source.Name = fi.Name()
|
||||||
db.history.Logs.Chunk = emptyChunk
|
db.history.Logs.Chunk = emptyChunk
|
||||||
db.lock.Unlock()
|
db.lock.Unlock()
|
||||||
case err := <-watcher.Errors:
|
|
||||||
if err != nil {
|
|
||||||
log.Warn("Fs watcher error", "err", err)
|
|
||||||
}
|
|
||||||
case <-ticker.C: // Send log updates to the client.
|
case <-ticker.C: // Send log updates to the client.
|
||||||
if opened == nil {
|
if opened == nil {
|
||||||
log.Warn("The last log file is not opened")
|
log.Warn("The last log file is not opened")
|
||||||
|
|
|
||||||
21
vendor/github.com/mohae/deepcopy/LICENSE
generated
vendored
Normal file
21
vendor/github.com/mohae/deepcopy/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Joel
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
8
vendor/github.com/mohae/deepcopy/README.md
generated
vendored
Normal file
8
vendor/github.com/mohae/deepcopy/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
deepCopy
|
||||||
|
========
|
||||||
|
[](https://godoc.org/github.com/mohae/deepcopy)[](https://travis-ci.org/mohae/deepcopy)
|
||||||
|
|
||||||
|
DeepCopy makes deep copies of things: unexported field values are not copied.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
cpy := deepcopy.Copy(orig)
|
||||||
125
vendor/github.com/mohae/deepcopy/deepcopy.go
generated
vendored
Normal file
125
vendor/github.com/mohae/deepcopy/deepcopy.go
generated
vendored
Normal file
|
|
@ -0,0 +1,125 @@
|
||||||
|
// deepcopy makes deep copies of things. A standard copy will copy the
|
||||||
|
// pointers: deep copy copies the values pointed to. Unexported field
|
||||||
|
// values are not copied.
|
||||||
|
//
|
||||||
|
// Copyright (c)2014-2016, Joel Scoble (github.com/mohae), all rights reserved.
|
||||||
|
// License: MIT, for more details check the included LICENSE file.
|
||||||
|
package deepcopy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Interface for delegating copy process to type
|
||||||
|
type Interface interface {
|
||||||
|
DeepCopy() interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iface is an alias to Copy; this exists for backwards compatibility reasons.
|
||||||
|
func Iface(iface interface{}) interface{} {
|
||||||
|
return Copy(iface)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy creates a deep copy of whatever is passed to it and returns the copy
|
||||||
|
// in an interface{}. The returned value will need to be asserted to the
|
||||||
|
// correct type.
|
||||||
|
func Copy(src interface{}) interface{} {
|
||||||
|
if src == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the interface a reflect.Value
|
||||||
|
original := reflect.ValueOf(src)
|
||||||
|
|
||||||
|
// Make a copy of the same type as the original.
|
||||||
|
cpy := reflect.New(original.Type()).Elem()
|
||||||
|
|
||||||
|
// Recursively copy the original.
|
||||||
|
copyRecursive(original, cpy)
|
||||||
|
|
||||||
|
// Return the copy as an interface.
|
||||||
|
return cpy.Interface()
|
||||||
|
}
|
||||||
|
|
||||||
|
// copyRecursive does the actual copying of the interface. It currently has
|
||||||
|
// limited support for what it can handle. Add as needed.
|
||||||
|
func copyRecursive(original, cpy reflect.Value) {
|
||||||
|
// check for implement deepcopy.Interface
|
||||||
|
if original.CanInterface() {
|
||||||
|
if copier, ok := original.Interface().(Interface); ok {
|
||||||
|
cpy.Set(reflect.ValueOf(copier.DeepCopy()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle according to original's Kind
|
||||||
|
switch original.Kind() {
|
||||||
|
case reflect.Ptr:
|
||||||
|
// Get the actual value being pointed to.
|
||||||
|
originalValue := original.Elem()
|
||||||
|
|
||||||
|
// if it isn't valid, return.
|
||||||
|
if !originalValue.IsValid() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cpy.Set(reflect.New(originalValue.Type()))
|
||||||
|
copyRecursive(originalValue, cpy.Elem())
|
||||||
|
|
||||||
|
case reflect.Interface:
|
||||||
|
// If this is a nil, don't do anything
|
||||||
|
if original.IsNil() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Get the value for the interface, not the pointer.
|
||||||
|
originalValue := original.Elem()
|
||||||
|
|
||||||
|
// Get the value by calling Elem().
|
||||||
|
copyValue := reflect.New(originalValue.Type()).Elem()
|
||||||
|
copyRecursive(originalValue, copyValue)
|
||||||
|
cpy.Set(copyValue)
|
||||||
|
|
||||||
|
case reflect.Struct:
|
||||||
|
t, ok := original.Interface().(time.Time)
|
||||||
|
if ok {
|
||||||
|
cpy.Set(reflect.ValueOf(t))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Go through each field of the struct and copy it.
|
||||||
|
for i := 0; i < original.NumField(); i++ {
|
||||||
|
// The Type's StructField for a given field is checked to see if StructField.PkgPath
|
||||||
|
// is set to determine if the field is exported or not because CanSet() returns false
|
||||||
|
// for settable fields. I'm not sure why. -mohae
|
||||||
|
if original.Type().Field(i).PkgPath != "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
copyRecursive(original.Field(i), cpy.Field(i))
|
||||||
|
}
|
||||||
|
|
||||||
|
case reflect.Slice:
|
||||||
|
if original.IsNil() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Make a new slice and copy each element.
|
||||||
|
cpy.Set(reflect.MakeSlice(original.Type(), original.Len(), original.Cap()))
|
||||||
|
for i := 0; i < original.Len(); i++ {
|
||||||
|
copyRecursive(original.Index(i), cpy.Index(i))
|
||||||
|
}
|
||||||
|
|
||||||
|
case reflect.Map:
|
||||||
|
if original.IsNil() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cpy.Set(reflect.MakeMap(original.Type()))
|
||||||
|
for _, key := range original.MapKeys() {
|
||||||
|
originalValue := original.MapIndex(key)
|
||||||
|
copyValue := reflect.New(originalValue.Type()).Elem()
|
||||||
|
copyRecursive(originalValue, copyValue)
|
||||||
|
copyKey := Copy(key.Interface())
|
||||||
|
cpy.SetMapIndex(reflect.ValueOf(copyKey), copyValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
cpy.Set(original)
|
||||||
|
}
|
||||||
|
}
|
||||||
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
|
|
@ -291,6 +291,12 @@
|
||||||
"revision": "ad45545899c7b13c020ea92b2072220eefad42b8",
|
"revision": "ad45545899c7b13c020ea92b2072220eefad42b8",
|
||||||
"revisionTime": "2015-03-14T17:03:34Z"
|
"revisionTime": "2015-03-14T17:03:34Z"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"checksumSHA1": "2jsbDTvwxafPp7FJjJ8IIFlTLjs=",
|
||||||
|
"path": "github.com/mohae/deepcopy",
|
||||||
|
"revision": "c48cc78d482608239f6c4c92a4abd87eb8761c90",
|
||||||
|
"revisionTime": "2017-09-29T03:49:55Z"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "FYM/8R2CqS6PSNAoKl6X5gNJ20A=",
|
"checksumSHA1": "FYM/8R2CqS6PSNAoKl6X5gNJ20A=",
|
||||||
"path": "github.com/naoina/toml",
|
"path": "github.com/naoina/toml",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue