/
config.go
37 lines (28 loc) · 935 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) 2024 The nilgo authors
// Use of this source code is governed by a MIT license found in the LICENSE file.
package grpc
import (
"context"
"strings"
"github.com/nil-go/konf"
pb "github.com/nil-go/nilgo/grpc/pb/nilgo/v1"
)
// ConfigServiceServer is an implementation of [pb.ConfigServiceServer].
type ConfigServiceServer struct {
pb.UnimplementedConfigServiceServer
configs []*konf.Config
}
func (c ConfigServiceServer) Explain(_ context.Context, request *pb.ExplainRequest) (*pb.ExplainResponse, error) {
if len(c.configs) == 0 {
return &pb.ExplainResponse{Explanation: konf.Explain(request.GetPath())}, nil
}
path := request.GetPath()
var explanation strings.Builder
for _, config := range c.configs {
if explanation.Len() > 0 {
explanation.WriteString("\n-----\n")
}
explanation.WriteString(config.Explain(path))
}
return &pb.ExplainResponse{Explanation: explanation.String()}, nil
}