github.com/m-lab/locate@v0.17.6/api/v2/scanner.go (about)

     1  package v2
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  )
     7  
     8  // RedisScan determines how Registration objects will be interpreted when
     9  // read from Redis.
    10  func (r *Registration) RedisScan(x interface{}) error {
    11  	v, ok := x.([]byte)
    12  	if !ok {
    13  		return fmt.Errorf("failed to convert %T to []byte", x)
    14  	}
    15  	return json.Unmarshal(v, r)
    16  }
    17  
    18  // RedisScan determines how Health objects will be interpreted when read
    19  // from Redis.
    20  func (h *Health) RedisScan(x interface{}) error {
    21  	v, ok := x.([]byte)
    22  	if !ok {
    23  		return fmt.Errorf("failed to convert %T to []byte", x)
    24  	}
    25  	return json.Unmarshal(v, h)
    26  }
    27  
    28  // RedisScan determines how Prometheus objects will be interpreted when read
    29  // from Redis.
    30  func (h *Prometheus) RedisScan(x interface{}) error {
    31  	v, ok := x.([]byte)
    32  	if !ok {
    33  		return fmt.Errorf("failed to convert %T to []byte", x)
    34  	}
    35  	return json.Unmarshal(v, h)
    36  }