state: add method to encode config into response message

This commit is contained in:
Evgeniy Kulikov 2019-12-17 14:09:52 +03:00
parent 11eb541f23
commit 55b9a2447c
No known key found for this signature in database
GPG key ID: BF6AEE0A2A699BF2
3 changed files with 111 additions and 0 deletions

View file

@ -1,9 +1,12 @@
package state
import (
"encoding/json"
"github.com/golang/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go"
"github.com/spf13/viper"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@ -46,3 +49,14 @@ func DecodeMetrics(r *MetricsResponse) ([]*MetricFamily, error) {
return metrics, nil
}
// EncodeConfig encodes viper settings into DumpConfig message,
// if something went wrong returns gRPC Status error (can be returned from service).
func EncodeConfig(v *viper.Viper) (*DumpResponse, error) {
data, err := json.Marshal(v.AllSettings())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &DumpResponse{Config: data}, nil
}