Files
query-orchestration/internal/client/service.go
T
Jay Brown 15adaebfcd Merged in feature/serviceconfig-integration (pull request #38)
DRAFT PR : WIP working through ideas for integration

* movearound

* attempttwo

* openapi

* further sanding

* fix

* start on tests

* runthroughsingleconfig

* somechanges

* reflectissue

* removeerrs

* mostlyremovepanic

* removeenv

* noncfgtests

* go

* repo

* fix service config test

* add PWD to all

* test fix

* fix lint

* todo for later

* passingunittests

* alltests

* testlogger

* testloggername

* clean
2025-01-31 13:43:55 +00:00

81 lines
1.1 KiB
Go

package client
import (
"errors"
"fmt"
"queryorchestration/internal/serviceconfig"
"regexp"
"strings"
"github.com/google/uuid"
)
type Client struct {
ID uuid.UUID
Name string
CanSync bool
}
func (c *Client) normalizeCanSyncUpdate(n **bool) {
if n == nil || *n == nil {
return
}
if c.CanSync == **n {
*n = nil
}
}
func (c *Client) normalizeNameUpdate(n **string) error {
if n == nil || *n == nil {
return nil
}
err := normalizeName(*n)
if err != nil {
return err
}
if c.Name == **n {
*n = nil
}
return nil
}
func normalizeName(name *string) error {
if name == nil {
return nil
}
uname := strings.TrimSpace(*name)
if uname == "" {
return errors.New("name required")
}
spacere := regexp.MustCompile(`\s+`)
uname = spacere.ReplaceAllString(uname, " ")
reg := `^[a-zA-Z0-9\_\- ]+$`
alphanumeric := regexp.MustCompile(reg)
if !alphanumeric.MatchString(uname) {
return fmt.Errorf("name must have regex: %s", reg)
}
*name = uname
return nil
}
type Service struct {
cfg serviceconfig.ConfigProvider
}
func New(cfg serviceconfig.ConfigProvider) *Service {
return &Service{
cfg,
}
}