Chore: use any rather than interface{} (#74066)
This commit is contained in:
@@ -40,7 +40,7 @@ func (s *Service) testGetHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
func (s *Service) getScenariosHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
result := make([]interface{}, 0)
|
||||
result := make([]any, 0)
|
||||
|
||||
scenarioIds := make([]string, 0)
|
||||
for id := range s.scenarios {
|
||||
@@ -50,7 +50,7 @@ func (s *Service) getScenariosHandler(rw http.ResponseWriter, req *http.Request)
|
||||
|
||||
for _, scenarioID := range scenarioIds {
|
||||
scenario := s.scenarios[scenarioID]
|
||||
result = append(result, map[string]interface{}{
|
||||
result = append(result, map[string]any{
|
||||
"id": scenario.ID,
|
||||
"name": scenario.Name,
|
||||
"description": scenario.Description,
|
||||
@@ -108,7 +108,7 @@ func createJSONHandler(logger log.Logger) http.Handler {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
logger.Debug("Received resource call", "url", req.URL.String(), "method", req.Method)
|
||||
|
||||
var reqData map[string]interface{}
|
||||
var reqData map[string]any
|
||||
if req.Body != nil {
|
||||
defer func() {
|
||||
if err := req.Body.Close(); err != nil {
|
||||
@@ -128,9 +128,9 @@ func createJSONHandler(logger log.Logger) http.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
data := map[string]interface{}{
|
||||
data := map[string]any{
|
||||
"message": "Hello world from test datasource!",
|
||||
"request": map[string]interface{}{
|
||||
"request": map[string]any{
|
||||
"method": req.Method,
|
||||
"url": req.URL,
|
||||
"headers": req.Header,
|
||||
|
||||
@@ -249,18 +249,18 @@ type JSONModel struct {
|
||||
Alias string `json:"alias"`
|
||||
// Cannot specify a type for csvWave since legacy queries
|
||||
// does not follow the same format as the new ones (and there is no migration).
|
||||
CSVWave interface{} `json:"csvWave"`
|
||||
CSVContent string `json:"csvContent"`
|
||||
CSVFileName string `json:"csvFileName"`
|
||||
DropPercent float64 `json:"dropPercent"`
|
||||
CSVWave any `json:"csvWave"`
|
||||
CSVContent string `json:"csvContent"`
|
||||
CSVFileName string `json:"csvFileName"`
|
||||
DropPercent float64 `json:"dropPercent"`
|
||||
}
|
||||
|
||||
type pulseWave struct {
|
||||
TimeStep int64 `json:"timeStep"`
|
||||
OnCount int64 `json:"onCount"`
|
||||
OffCount int64 `json:"offCount"`
|
||||
OnValue interface{} `json:"onValue"`
|
||||
OffValue interface{} `json:"offValue"`
|
||||
TimeStep int64 `json:"timeStep"`
|
||||
OnCount int64 `json:"onCount"`
|
||||
OffCount int64 `json:"offCount"`
|
||||
OnValue any `json:"onValue"`
|
||||
OffValue any `json:"offValue"`
|
||||
}
|
||||
|
||||
func GetJSONModel(j json.RawMessage) (JSONModel, error) {
|
||||
@@ -1001,7 +1001,7 @@ func randomHeatmapData(query backend.DataQuery, fnBucketGen func(index int) floa
|
||||
|
||||
for j := int64(0); j < 100 && timeWalkerMs < to; j++ {
|
||||
t := time.Unix(timeWalkerMs/int64(1e+3), (timeWalkerMs%int64(1e+3))*int64(1e+6))
|
||||
vals := []interface{}{&t}
|
||||
vals := []any{&t}
|
||||
for n := 1; n < len(frame.Fields); n++ {
|
||||
v := float64(rand.Int63n(100))
|
||||
vals = append(vals, &v)
|
||||
@@ -1104,7 +1104,7 @@ func frameNameForQuery(query backend.DataQuery, model JSONModel, index int) stri
|
||||
return name
|
||||
}
|
||||
|
||||
func fromStringOrNumber(val interface{}) (*float64, error) {
|
||||
func fromStringOrNumber(val any) (*float64, error) {
|
||||
switch v := val.(type) {
|
||||
case float64:
|
||||
fV := val.(float64)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,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
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user