Chore: use any rather than interface{} (#74066)

This commit is contained in:
Ryan McKinley
2023-08-30 18:46:47 +03:00
committed by GitHub
parent 3e272d2bda
commit 025b2f3011
525 changed files with 2528 additions and 2528 deletions
+1 -1
View File
@@ -214,7 +214,7 @@ func (s *SimulationEngine) getSimFromPath(path string) (Simulation, error) {
}
func (s *SimulationEngine) GetSimulationHandler(rw http.ResponseWriter, req *http.Request) {
var result interface{}
var result any
path := req.URL.Path
if path == "/sims" {
v := make([]simulationInfo, 0, len(s.registry))
+1 -1
View File
@@ -15,7 +15,7 @@ func TestCoreSimulationRegistry(t *testing.T) {
Type: "flight",
TickHZ: 1,
},
Config: map[string]interface{}{
Config: map[string]any{
"period": 100,
"radius": 0.05,
},
+3 -3
View File
@@ -40,7 +40,7 @@ func (s *flightSim) GetState() simulationState {
}
}
func (s *flightSim) SetConfig(vals map[string]interface{}) error {
func (s *flightSim) SetConfig(vals map[string]any) error {
return updateConfigObjectFromJSON(s.cfg, vals)
}
@@ -60,10 +60,10 @@ func (s *flightSim) NewFrame(size int) *data.Frame {
return frame
}
func (s *flightSim) GetValues(t time.Time) map[string]interface{} {
func (s *flightSim) GetValues(t time.Time) map[string]any {
p := s.cfg.getNextPoint(t)
return map[string]interface{}{
return map[string]any{
"time": p.time,
"lat": p.lat,
"lng": p.lng,
@@ -22,7 +22,7 @@ func TestFlightPathQuery(t *testing.T) {
TickHZ: 1,
}
sq.Stream = true
sb, err := json.Marshal(map[string]interface{}{
sb, err := json.Marshal(map[string]any{
"sim": sq,
})
require.NoError(t, err)
+3 -3
View File
@@ -36,7 +36,7 @@ func (s *tankSim) GetState() simulationState {
}
}
func (s *tankSim) SetConfig(vals map[string]interface{}) error {
func (s *tankSim) SetConfig(vals map[string]any) error {
return updateConfigObjectFromJSON(&s.cfg, vals)
}
@@ -69,7 +69,7 @@ func (s *tankSim) NewFrame(size int) *data.Frame {
return frame
}
func (s *tankSim) GetValues(t time.Time) map[string]interface{} {
func (s *tankSim) GetValues(t time.Time) map[string]any {
if t.Before(s.state.Time) {
return nil // can not look backwards!
}
@@ -94,7 +94,7 @@ func (s *tankSim) GetValues(t time.Time) map[string]interface{} {
s.state.Time = t
}
return map[string]interface{}{
return map[string]any{
"time": s.state.Time,
"percentFull": s.state.FillPercent,
"tankVolume": s.state.FillPercent * s.cfg.TankCapacity,
+3 -3
View File
@@ -28,7 +28,7 @@ type simulationState struct {
Key simulationKey `json:"key"`
// Saved in panel options, and used to set initial values
Config interface{} `json:"config"`
Config any `json:"config"`
}
type simulationInfo struct {
@@ -45,7 +45,7 @@ type simulationInfo struct {
type Simulation interface {
io.Closer
GetState() simulationState
SetConfig(vals map[string]interface{}) error
SetConfig(vals map[string]any) error
NewFrame(size int) *data.Frame
GetValues(t time.Time) map[string]interface{}
GetValues(t time.Time) map[string]any
}
+8 -8
View File
@@ -8,7 +8,7 @@ import (
)
// updateConfigObjectFromJSON will use json serialization to update any properties
func updateConfigObjectFromJSON(cfg interface{}, input interface{}) error {
func updateConfigObjectFromJSON(cfg any, input any) error {
current, err := asStringMap(cfg)
if err != nil {
return err
@@ -33,12 +33,12 @@ func updateConfigObjectFromJSON(cfg interface{}, input interface{}) error {
return json.Unmarshal(b, cfg)
}
func asStringMap(input interface{}) (map[string]interface{}, error) {
v, ok := input.(map[string]interface{})
func asStringMap(input any) (map[string]any, error) {
v, ok := input.(map[string]any)
if ok {
return v, nil
}
v = make(map[string]interface{})
v = make(map[string]any)
b, err := json.Marshal(input)
if err != nil {
return nil, err
@@ -47,7 +47,7 @@ func asStringMap(input interface{}) (map[string]interface{}, error) {
return v, err
}
func setFrameRow(frame *data.Frame, idx int, values map[string]interface{}) {
func setFrameRow(frame *data.Frame, idx int, values map[string]any) {
for _, field := range frame.Fields {
v, ok := values[field.Name]
if ok {
@@ -56,7 +56,7 @@ func setFrameRow(frame *data.Frame, idx int, values map[string]interface{}) {
}
}
func appendFrameRow(frame *data.Frame, values map[string]interface{}) {
func appendFrameRow(frame *data.Frame, values map[string]any) {
for _, field := range frame.Fields {
v, ok := values[field.Name]
if ok {
@@ -67,8 +67,8 @@ func appendFrameRow(frame *data.Frame, values map[string]interface{}) {
}
}
func getBodyFromRequest(req *http.Request) (map[string]interface{}, error) {
result := make(map[string]interface{}, 10)
func getBodyFromRequest(req *http.Request) (map[string]any, error) {
result := make(map[string]any, 10)
err := json.NewDecoder(req.Body).Decode(&result)
// TODO? create the map based on form parameters not JSON post
+2 -2
View File
@@ -8,13 +8,13 @@ import (
)
func TestSimulationUtils(t *testing.T) {
a := map[string]interface{}{
a := map[string]any{
"hello": "world",
"bool": true,
"number": 10,
}
err := updateConfigObjectFromJSON(&a, map[string]interface{}{
err := updateConfigObjectFromJSON(&a, map[string]any{
"bool": false,
"number": 5,
})
+3 -3
View File
@@ -33,7 +33,7 @@ func (s *waveformSim) GetState() simulationState {
}
}
func (s *waveformSim) SetConfig(vals map[string]interface{}) error {
func (s *waveformSim) SetConfig(vals map[string]any) error {
return updateConfigObjectFromJSON(s.cfg, vals)
}
@@ -47,7 +47,7 @@ func (s *waveformSim) NewFrame(size int) *data.Frame {
return frame
}
func (s *waveformSim) GetValues(t time.Time) map[string]interface{} {
func (s *waveformSim) GetValues(t time.Time) map[string]any {
x := 0.0
if s.cfg.Period > 0 {
periodMS := s.cfg.Period * 1000
@@ -63,7 +63,7 @@ func (s *waveformSim) GetValues(t time.Time) map[string]interface{} {
v += (gen.Float64() * 2.0 * noise) - noise
}
return map[string]interface{}{
return map[string]any{
data.TimeSeriesTimeFieldName: t,
data.TimeSeriesValueFieldName: v,
}