Welcome to mirror list, hosted at ThFree Co, Russian Federation.

node.go « config « praefect « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0f02ba2514d53a417c6062690810e327d2a28c9d (plain)
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
package config

import (
	"encoding/json"
	"fmt"

	"gitlab.com/gitlab-org/gitaly/v16/internal/errors/cfgerror"
)

// Node describes an address that serves a storage
type Node struct {
	Storage string `toml:"storage,omitempty"`
	Address string `toml:"address,omitempty"`
	Token   string `toml:"token,omitempty"`
}

//nolint:revive // This is unintentionally missing documentation.
func (n Node) MarshalJSON() ([]byte, error) {
	return json.Marshal(map[string]interface{}{
		"storage": n.Storage,
		"address": n.Address,
	})
}

// String prints out the node attributes but hiding the token
func (n Node) String() string {
	return fmt.Sprintf("storage_name: %s, address: %s", n.Storage, n.Address)
}

// Validate runs validation on all fields and compose all found errors.
func (n Node) Validate() error {
	return cfgerror.New().
		Append(cfgerror.NotBlank(n.Storage), "storage").
		Append(cfgerror.NotBlank(n.Address), "address").
		AsError()
}