Other: Simple gRPC client/server under test

This commit is contained in:
James Houlahan
2022-11-03 10:43:25 +01:00
parent d093488522
commit 78fc5ec458
12 changed files with 477 additions and 121 deletions

View File

@ -22,15 +22,15 @@ import (
"os"
)
// config is a structure containing the service configuration data that are exchanged by the gRPC server and client.
type config struct {
// Config is a structure containing the service configuration data that are exchanged by the gRPC server and client.
type Config struct {
Port int `json:"port"`
Cert string `json:"cert"`
Token string `json:"token"`
}
// save saves a gRPC service configuration to file.
func (s *config) save(path string) error {
func (s *Config) save(path string) error {
// Another process may be waiting for this file to be available. In order to prevent this process to open
// the file while we are writing in it, we write it with a temp file name, then rename it.
tempPath := path + "_"
@ -41,7 +41,7 @@ func (s *config) save(path string) error {
return os.Rename(tempPath, path)
}
func (s *config) _save(path string) error {
func (s *Config) _save(path string) error {
f, err := os.Create(path) //nolint:errcheck,gosec
if err != nil {
return err
@ -53,7 +53,7 @@ func (s *config) _save(path string) error {
}
// load loads a gRPC service configuration from file.
func (s *config) load(path string) error {
func (s *Config) load(path string) error {
f, err := os.Open(path) //nolint:errcheck,gosec
if err != nil {
return err